Categories
ant deployment eclipse jar java

How do I change the destination directory of Ant’s fileset command?

I have an Ant buildfile for a Java library. It looks something like this:

<project ... ><target ... >
<jar destfile="C:\path\to\export.jar">
<manifest> ... </manifest>
<fileset dir="C:\path\to\bin" />
<fileset dir="C:\path\to\src" />
<fileset dir="C:\path\to\doc" />
<zipfileset src="https://www.faqcode4u.com/faq/338090/C:\path\to\included\library.jar" />
</jar>
</target></project>

The only problem is that my JavaDoc is being exported directly into the root directory of the resulting jar file. Essentialy, I’d like some equivalent of the <copydir> command that can be used inside the <jar> command.

My desired structure is this:

export.jar
META-INF
Manifest.MF
com
example
whatever
Blah.class
Blah.java
org
external
somelibrary
Magic.class // contents of the included library jar file
doc
// javadoc files here

The current structure is:

export.jar
META-INF
Manifest.MF
com
example
whatever
Blah.class
Blah.java
// some javadoc files here
org
external
somelibrary
Magic.class // contents of the included library jar file
// more javadoc files here


My current “solution” is to omit the documentation <fileset> command, then, once the jar has exported, go into Windows Explorer and right click7-ZipOpen Archive; I can then drop the doc directory in there just fine. However, this pretty completely defeats the purpose of Ant as a completely automated build system.

If it matters, this file was originally generated by Eclipse with the Runnable JAR exporter. However, I obviously need to modify it to add source files, etc. because it’s a library and not actually a runnable jar. I exported it as a runnable jar to get Eclipse to package in the required libraries; apparently libraries on the build path aren’t available for export via the standard FileExportJAR file.