开发者

NetBeans: Force external class to be statically compiled into JAR?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜