How do you include .jar files in a Java library so that it can be imported directly in a program?
hmm. using ant the folloeing may help
<target name="CreateExecutableJarFileWithExternalLibrary">
<jar destfile="MyApplication.jar">
<zipfileset dir="classes" prefix="" />
<zipfileset src="external.jar" />
<manifest>
<attribute name="Main-Class" value="mypackage.MyMainClass" />
</manifest>
</jar>
</target>
But you shall provide more information. In general I don't think that it's good style to provide a jar in a jar...
I think your question needs to be clarified.
But, either add them to your CLASSPATH environment variable or use -classpath on java.exe
I think you want to include a classpath entry in the MANIFEST.MF. I can't believe this question hasn't been already answered on SO. Here are the instructions. Best way to to this ist using the ant snippet from tuergeist, because fiddling with the classpath entry is a bit cumbersome.
UPDATE: This works also inside a EAR file. Most container do allow referencing JAR files inside the ear itself. The container has to use a special class loader for this.
Sounds like you want to bundle your project, including dependencies, into a single jar file.
Try one of the following:
- The unfortunately named Jar Jar Links
- One Jar
- I used to use Fat Jar Eclipse Plugin, which appears to be integrated into the latest Eclipse releases.
To clarify, you can't enclose jars within jars. If you're build a .jar
library, then you effectively have 2 options:
- build your
.jar
of your code, and specify the additional.jar
s to go alongside. They will have to be referenced on the classpath with your jar - or, explode the additional
.jar
s, and rejar with your code into one huge.jar
. That has the pro of being simple to manage, and the downside that you should be careful exploding and recombining jars in case there are duplicate classes and you get the wrong one (or omit non.class
resources etc.)