Sharing Project Libraries in NetBeans IDE 6.1
Contents
To follow this tutorial, you need the following software and resources.
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:
- Choose File > New Project.
- In the Java category of the wizard, select one of the standard templates.
Then click Next.
- In the Name and Location page of the wizard, select the
Use Dedicated Folder for Sharing Libraries checkbox.
- 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:
- Choose File > New Project.
- In the Web category of the wizard, select one of the standard templates.
Then click Next.
- In the Name and Location page of the wizard, select the
Use Dedicated Folder for Sharing Libraries checkbox.
- 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.
- (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:
- Right-click the project's node and choose Properties.
- In the Project Properties dialog box, select the Libraries node.
- In the Libraries panel, click Browse to open the New Libraries Folder wizard.
- 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.
- 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.
- Click Finish to exit the Make Project Sharable wizard.
- 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.