I have a NetBeans project that relies on one specific Java class in another project. Right now, when NetBeans compiles the project, it only adds a reference to the other Java class, which leads to a NoClassDefFoundError since the external class isn't in the JAR.
How can I开发者_JAVA百科 force NetBeans to compile that external file into the JAR when it builds, short of copying and pasting it over?
I take it that you are trying to create what it commonly known as a "fat JAR file"; i.e. a JAR file that contains all required classes for your application.
Try the recipe in this forum posting.
Another alternative might be to add something like the following to your Ant buld.xml
file.
<target name="-post-jar">
<jar update="true" destfile="${dist.jar}">
<zipfileset src="${javac.classpath}"/>
</jar>
</target>
If it's Maven based, simply use the ant task to copy the class to your target/classes in the appropriate phase (I guess compile-sources or such - something before test
).
If it's Ant based, you'd have to hack NetBeans' ant build scripts, which are extensible per-project.
BTW, the standard way is to make the "another project" a dependency of your project. That class might need another classes from that project... and so on.
I might also recommend JDGUI to decompile that project and to cherry-pick the classes you need. http://java.decompiler.free.fr/?q=jdgui
精彩评论