Search code examples
antjava-10netbeans-9

Netbeans 9.0 Incubating - Does not make `lib` directory in `dist` for migrated/updated Java 10 project


I have started using NetBeans 9.0 (incubating) with Java 10. I created a new test Java Application project and ticked 'Use Dedicated Folder for Storing Libraries' ('\lib') when creating it. I also set the JDK/Java version to 10. I then included Apache Commons Codec 1.11 as a dependency library. I didn't do anything else, other than import the Base64 class from the binary package in the main class.

However, when I build the application, NetBeans doesn't create a lib directory in the dist directory, nor does it create a fat Jar that includes the org.apache.commons.codec.* package(s) from the library.

This seems specific to Java 10, because it behaved as expected (copied libraries across) when I changed the JDK/Java version to 8.

Edit: I have seen various answers to other questions (about other versions of Netbeans and Java) that put forth various target and condition fragments to place in the build scripts to override build-impl.xml, which I have tried to no effect.

This leaves two questions?

  1. Does Netbeans 9.0 not fully support Java 10, causing the copyLibs task to fail silently?
  2. Does Java 10 not support creating a lib directory relative to the application jar or am I failing to configure the project correctly?

Note: The purpose of the test project was to diagnose if I could reproduce an issue affecting a larger project that needs to be updated to use a newer version of Java. The old project uses a number of libraries developed internally by the company for which I work. We do not have the resources necessary to set up and migrate to a Maven-based build system and are still using Ant.


Solution

  • I can reproduce your problem.

    Unfortunately this is a NetBeans 9.0 bug. See NETBEANS-1097 "Copy Dependent Libraries" does not work if "Source/Binary Format" is JDK 9 or JDK 10.

    That bug describes a possible workaround which is also mentioned in Halvor's answer. However, although that does not appear to work for you (based on your comment), it partially worked for me:

    • Edit nbproject/build-impl.xml as detailed in the bug.
    • Clean and build the project.
    • After doing that commons-codec-1.11.jar is placed in directory dist/lib.
    • However, I still did not get the fat jar.

    One other thing I tried was {project } > right click > Properties > Libraries, then editing the Libraries Folder field, changing it from a relative path to an absolute path. That did not seem to make things better or worse.