简体   繁体   中英

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="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 .

A jar is actually like a zip file. Hence you can use a zipfileset . Its attribute prefix is what you are looking for.

The zipfileset command can accept either a zip file via src or a filesystem directory via dir . Using the latter, you can add the following command:

<zipfileset dir="C:\path\to\doc" prefix="doc" />

Also worth to note is that zipfileset supports all attributes of fileset. Thus if you want to include just a single file in a specific location you can use:

<zipfileset file="C:\path\to\doc\file.txt" prefix="doc" />

Further reading: http://ant.apache.org/manual/Types/zipfileset.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM