Archive

Posts Tagged ‘netbeans’

Adding custom Class-Path entries to a Netbeans Java Application Project

August 31, 2012 Leave a comment

I want to jot this down before I forget. I was working in a Netbeans Java Application project, but I wanted to augment the Class-Path of the MANIFEST.MF in the Jar file to include an additional location.

If you’ve looked at a project, you’ll notice that Netbeans does create a MANIFEST.MF itself, but if you attempt to add a Class-Path property by hand, it will get bundled verbatim, so any additional libraries that Netbeans would have added for you don’t get added.

I ended up with this solution. I added this to the build.xml file

<target name="-pre-jar">
    <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
    <pathconvert property="run.classpath.without.build.classes.dir">
        <path path="${run.classpath}"/>
        <map from="${build.classes.dir.resolved}" to=""/>
    </pathconvert>
    <pathconvert pathsep=" " property="jar.classpath">
        <path path="${run.classpath.without.build.classes.dir}"/>
        <chainedmapper>
            <flattenmapper/>
            <globmapper from="*" to="lib/*"/>
        </chainedmapper>
    </pathconvert>
    <manifest file="MANIFEST.MF">
        <attribute name="Class-Path" value="${jar.classpath} lib/"/>
    </manifest>
</target>

Most of the meat of the target is taken from nbproject/build-impl.xml, the only thing I have really done is add the desired paths to the “Class-Path” line, in this case I just added “lib/” in there.

Categories: Computing Tags: ,