I had the same problem and I wrote an ant task to automatically copy the dependent libraries from all included class-library projects into my main-project(s). You don't need to include any third party libraries for this to run.
The Copy Dependent Libraries checkbox in the class-library project options must be set for this to work. Then Netbeans copies all dependent libraries into the class-library project's dist/lib folder, similar to Gregory's solution. The advantage of this method is, when you include more class-libraries to your main-project, you don't need to adapt your build.xml each time.
How it works
My ant task first searches the main-project's properties for the paths of all included projects, then opens their project.properties file, reads the class-library project's dist-folder and copies all libraries in the dist-folder's lib directory to the main-project's lib folder.
There is also a test if Copy Dependent Libraries is enabled.
The code
The file build-import-libraries.xml in the project's parent folder :
<?xml version="1.0" encoding="UTF-8"?>
<!--
Custom import of libraries.
This is not done in Netbeans, because the dist folder is created at runtime.
To work correctly, disable the compile on save feature for your project.
Author: Christophe Weis
-->
<project name="IncludeLibraries" default="default" basedir=".">
<description>Includes dependent libraries in projects using class-library projects.</description>
<dirname property="IncludeLibraries.basedir" file="${ant.file.IncludeLibraries}"/>
<target name="copy-files">
<!-- Set variable to the folder where to copy the files to -->
<condition property="libdestdir" value="${build.web.dir}/WEB-INF/lib" else="${dist.dir}/lib">
<isset property="build.web.dir"/>
</condition>
<echo message="Custom build step in file '${ant.file}': copying dependent libraries from included Netbeans projects to '${libdestdir}'" level="info"/>
<echo message="Please make sure that 'Copy Dependent Libraries' is enabled in Netbeans project options for each included project" level="info"/>
<copy-dependent-libs>
<propertyset id="properties-starting-with-project">
<propertyref prefix="project."/>
</propertyset>
</copy-dependent-libs>
</target> <!-- End custom import -->
<scriptdef name="copy-dependent-libs" language="javascript">
<element name="propertyset" type="propertyset"/>
<![CDATA[
// Ant uses the Rhino JavaScript implementation
propertySets = elements.get("propertyset");
// loop all nested property sets
for (i = 0; i < propertySets.size(); ++i) {
propertySet = propertySets.get(i);
properties = propertySet.getProperties();
for (var iterator = properties.entrySet().iterator(); iterator.hasNext();) {
var entry = iterator.next();
var key = entry.getKey();
if ("project.licensePath".equals(key)) {
continue;
}
var value = entry.getValue();
// read the referenced project's property file
var file = new java.io.File(project.getBaseDir(), value + "/nbproject/project.properties");
var inputStream = new java.io.FileInputStream(file);
var projectProperties = new java.util.Properties();
projectProperties.load(inputStream);
inputStream.close();
var distFolder = projectProperties.getProperty("dist.dir");
// check if 'Copy Dependent Libraries' is enabled
var doNotCopyDependentLibraries = projectProperties.getProperty("mkdist.disabled");
doNotCopyDependentLibraries = java.lang.Boolean.parseBoolean(doNotCopyDependentLibraries);
if (doNotCopyDependentLibraries) {
self.fail("Please enable 'Copy Dependent Libraries' in project properties for project " + projectProperties.getProperty("application.title", value));
}
t = project.createTask("copy-files-from-libfolder");
// set the dist folder's lib directory
t.setDynamicAttribute("fromdir", value + "/" + distFolder + "/lib");
t.perform();
}
}
]]>
</scriptdef>
<macrodef name="copy-files-from-libfolder">
<attribute name="fromdir" />
<sequential>
<echo message="Copying libraries from directory '@{fromdir}' to '${libdestdir}'" level="verbose" />
<copy todir="${libdestdir}">
<fileset dir="@{fromdir}">
<!-- Enable this if you wish
<exclude name="servlet-api.jar"/>
-->
</fileset>
</copy>
</sequential>
</macrodef>
</project>
Include this line in your build.xml, after <import file="nbproject/build-impl.xml"/>
(you may need to adapt the path to build-import-libraries.xml in the import task) :
<!--
Custom import of libraries.
-->
<import file="../build-import-libraries.xml" as="include-libraries" />
<target name="-post-compile" depends="include-libraries.copy-files" />
This works for Java SE Applications and Java Web Applications. I have only tested this in Netbeans version 8.0.2. I hope this will keep working in future versions.
lib
folder. – Gallaher