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

假装没事ソ 提交于 2019-12-07 20:46:59

问题


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.


回答1:


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.




回答2:


One workaround for this problem appears to be modifying your build-impl.xml.

Find the following condition:

<condition property="do.mkdist">
    <and>
        <isset property="do.archive"/>
        <isset property="libs.CopyLibs.classpath"/>
        <not>
            <istrue value="${mkdist.disabled}"/>
        </not>
        <not>
            <istrue value="${modules.supported.internal}"/>
        </not>
    </and>
</condition>

And remove the segment regarding modules.supported.internal, leaving you with:

<condition property="do.mkdist">
    <and>
        <isset property="do.archive"/>
        <isset property="libs.CopyLibs.classpath"/>
        <not>
            <istrue value="${mkdist.disabled}"/>
        </not>
    </and>
</condition>

Unfortunately NetBeans will overwrite this change at times, but it should still function as a workaround.



来源:https://stackoverflow.com/questions/52408574/netbeans-9-0-incubating-does-not-make-lib-directory-in-dist-for-migrated-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!