问题
My application relies on two external libraries, I have both in jar
format and have added them to my classpath, making it possible to run my application within NetBeans.
However, I would like to package my application in an easy to use jar
file. When I tried the automatic method of jar
creation provided by NetBeans (where it auto generates a jarfile in dist/
) and ran it on another computer, I got lots of ClassNotFound (or similar) exceptions for classes that I could tell were supposed to be provided by my other libraries.
Is there a way I can include the other jarfiles I have into my own jar? I've never created an application which relies on other libraries before so this is a first for me.
回答1:
You can add a "Class-path" line to your jar's manifest. The drawback is that you have to hard code the paths to a file system (not jar) location in the manifest. If you put them all in the same directory or a consistent relative directory, it should be manageable.
See: http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
Alternately you can try something line One-JAR: http://one-jar.sourceforge.net/
来源:https://stackoverflow.com/questions/8334588/how-to-package-libraries-into-my-jar-using-ant