I want to create a jar with the following directory structure:
thejar.jar/
classes/ --> where all classes go
lib/ --> where all dependencies go
res/ --> where all non-classpath resources go (scripts, etc.)
META-INF/
Here’s my ant task:
<jar destfile="dist/main/thejar.jar">
<!-- Create the manifest -->
<manifest>
<!-- JAR should be sealed. -->
<attribute name="Sealed" value="true" />
</manifest>
<!-- Copy main build directory to classes/ directory in JAR. -->
<fileset dir="dist/main/classes" includes="build/main"/>
<!-- Copy main library directory to lib/ directory in JAR. -->
<fileset dir="dist/main/lib" includes="lib/main"/>
<!-- Copy main resources directory to res/ in JAR. -->
<fileset dir="dist/main/res" includes="res/main"/>
</jar>
If I am understanding this correctly, it should be:
- Copying all the built (.class) files in
build/maintodist/main/classes - Copying all
lib/maindependencies todist/main/lib - Copying all
res/mainfiles todist/main/res - JARring up
dist/main/*intothejar.jar
The JAR task executes without errors, but when I go to view the contents of thejar.jar I just see META-INF/ (none of the subdirectories I mentioned above).
What’s going on here? Thanks in advance!
You want
jartask to copy files inbuild/maininto jar’sdist/main/lib, butmeans to pack files in
dist/main/classes/build/maininto the jar file.Take a look at the example from the Ant-Jar task doc:
To achieve your request, I think you can copy the classes, resources and dependencies with
<copy>task into the directory structure that you want and then jar the directory.