FeaturesPluginsDocs & SupportCommunityPartners

Sharing Project Libraries in NetBeans IDE 6.1

Contents

Content on this page applies to NetBeans IDE 6.0

To follow this tutorial, you need the following software and resources.

Software or Resource Version Required
NetBeans IDE version 6.1
Java Developer Kit (JDK) version 6 or
version 5

Project Sharability

As the NetBeans IDE project system is Ant-based, NetBeans projects are already generally portable between different users, whether or not they use the IDE. Project metadata is stored in a combination of human-readable XML and properties files. Projects can be built outside of the IDE by merely by running the Ant script.

However, one inconvenience has been that the project build script's way of referring to libraries has been dependent on factors specific to each user, particularly in the case of libraries defined in the Library Manager dialog box.

So, for example, if you had a project that depended on a custom library that you had specified in the Libraries window and you wanted somebody else to look at the project, you could send it to him or her in a zip file. But they might initially have problems building the project because of unresolved references to the custom library.

Another inconvenience is that libraries are stored in a variety of locations, based on where they originate. Libraries that come with the IDE are stored in various different folders within the IDE's installation. Examples of these include the libraries for the Swing Layout Extensions, beans binding, and database drivers.

In NetBeans IDE 6.1, the project system has been enhanced to offer more options for handling libraries that your project needs on its classpath. This flexibility makes it easier for you to handle the following situations:

  • You create a project and need to make it available and buildable to other users, whether they use the IDE or not. They should be able to access the project through a version control checkout or by unpacking a zip file that you have provided them. Then they should be able build the application without extra configuration.
  • You must start working on an existing project and adhere to a strict set of conventions concerning where project libraries are stored (and whether your build script accesses them with a relative reference or absolute reference). Other users on the team are not using the NetBeans IDE and have no plans to switch.

NetBeans IDE 6.1 allows you to solve both of these types of situations by explicitly setting a location for the libraries on which your project relies. Furthermore, you have control over whether to use an relative path or an absolute path when referring to these libraries. From here on in this article, we will refer to these features as making a project "sharable".

Configuring Library Location

You can configure standard Java SE, Web, and Enterprise projects to be sharable. You can make a project sharable when you create the project (in the New Project wizard) or afterwards in the Libraries tab of the Project Properties dialog box.

To make a general Java project's libraries sharable upon project creation:

  1. Choose File > New Project.
  2. In the Java category of the wizard, select one of the standard templates. Then click Next.
  3. In the Name and Location page of the wizard, select the Use Dedicated Folder for Sharing Libraries checkbox.
  4. In the Libraries field, select the location for the libraries to be stored.

    If the libraries are already included in the IDE, those libraries will be copied to the folder that you have designated.

To make a web or Java EE project's libraries sharable upon project creation:

  1. Choose File > New Project.
  2. In the Web category of the wizard, select one of the standard templates. Then click Next.
  3. In the Name and Location page of the wizard, select the Use Dedicated Folder for Sharing Libraries checkbox.
  4. In the Libraries field, select the location for the libraries to be stored.

    If the libraries are already included in the IDE, those libraries will be copied to the folder that you have designated.

  5. (Optional) On the Server and Settings page, select the Copy Server JAR Files to Libraries Folder radio button.

To make an existing project's libraries sharable:

  1. Right-click the project's node and choose Properties.
  2. In the Project Properties dialog box, select the Libraries node.
  3. In the Libraries panel, click Browse to open the New Libraries Folder wizard.
  4. In the Library Folder page of the wizard, enter a location for the libraries and click Next.

    You can enter the location as a relative reference or an absolute reference.

  5. In the Actions panel of the wizard, verify the selected action for each listed library. In most cases, the IDE detects the most appropriate action for that library.

    The following actions are available:

    • Copy Library JAR Files to New Libraries Folder. Use this option if the library is not in the folder that you have selected and you want to have the library JAR files placed there.
    • Use Relative Path to Library JAR Files. Use this option if the library is not in the libraries folder and you need to access the library in its existing location using a relative path. An entry with a relative reference is added for the library in the libraries folder's nblibraries.properties file.
    • Use Absolute Path to Library JAR Files. Use this option if the library is not in the libraries folder and you need to access the library in its existing location using an absolute path. An entry with an absolute reference is added for the library in the libraries folder's nblibraries.properties file.
    • Use Existing Library in Libraries Folder. Use this option if there is already a copy of the library in the libraries folder and you want to use that copy of the library.
  6. Click Finish to exit the Make Project Sharable wizard.
  7. Click OK to exit the Project Properties dialog box.

Notes:

  • You can also use the Libraries node of the Project Properties dialog box to change the location of the libraries folder. If you have already specified a libraries folder, clicking Browse opens a file chooser instead of the New Libraries Folder wizard.
  • Free-form project libraries can not be sharable in the ways described in this topic.
  • The New Project wizard does not include the sharable libraries option for some standard project templates, such as the Java Desktop Application. However, you can make such projects sharable in the Project Properties dialog box.

Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Open ESB - The Open Enterprise Service Bus Powered by