Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7884843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:54:33+00:00 2026-06-03T04:54:33+00:00

I have an Ant file where I am creating a zip file and a

  • 0

I have an Ant file where I am creating a zip file and a manifest for several JAR files. Both the zip and the manifest reference the same libraries, but in slightly different ways. If possible I would like to combine the references to the files instead of explicitly writing them twice and hoping the references in both tasks sync up. Below is an example of what I am currently doing.

<target name="zip" depends="default">
  <zip destfile="${dist.dir}/${project.name}_v${project.version}.zip">
    <zipfileset prefix="lib" dir="lib/Dom4J" includes="*.jar"/>
    <zipfileset prefix="lib" dir="lib/GSON" includes="*.jar"/>
    <zipfileset prefix="lib" dir="lib/Guava" includes="*.jar"/>
    <!-- ... A bunch more (Note I don't want everything 
             in the lib directory, just certain subfolders 
             within the lib directory which are explicitly 
             listed here like GSON. -->
    </zip>
</target>

<target name="createManifest">
   <!-- Hard code the classpath by hand and hope 
        they sync up with the zip task -->
   <property name="mfClasspath" 
             value="dom4j-1.6.1.jar gson-2.1.jar guava-11.0.2.jar" />
   <!-- Code to use the mfClasspath when creating the manifest 
        omitted for brevity -->
</target>

What I would ideally like to have is a fileset of some sort that I could reference in both tasks. Note that the manifest does not contain any folders/paths. The manifest only contains the JAR files found within the directories mentioned in the zip task.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:54:35+00:00Added an answer on June 3, 2026 at 4:54 am

    You are right. You can accomplish this with a common fileset shared by both the zip and createManifest tasks. For the zip task, copy the files to a temporary location and then zip them up.

    For the createManifest task, use character replacement to remove the folders from the paths. Character-replacement strategies are discussed in “Replacing characters in Ant property.” If you have Ant-Contrib, you can simplify the character-replacement algorithm below by using the PropertyRegex Ant task.

    <project default="all">
        <fileset id="jars" dir=".">
            <include name="lib/Dom4J/dom4j-1.6.1.jar" />
            <include name="lib/GSON/gson-2.1.jar" />
            <include name="lib/Guava/guava-11.0.2.jar" />
        </fileset>
    
        <target name="zip">
            <copy todir="tmp.dir" flatten="true">
                <fileset refid="jars" />
            </copy>
            <zip destfile="example.zip">
                <zipfileset dir="tmp.dir" prefix="lib" />
            </zip>
            <delete dir="tmp.dir" />
        </target>
    
        <target name="createManifest">
            <property name="jars.property" refid="jars" />
            <echo message="${jars.property}" file="some.tmp.file" />
            <loadfile property="mfClasspath" srcFile="some.tmp.file">
                <filterchain>
                    <tokenfilter>
                        <replaceregex pattern="(?:[^;/]+/)+?([^;/]+\.jar)"
                            replace="\1" flags="g" />
                        <replacestring from=";" to=" " />
                    </tokenfilter>
                </filterchain>
            </loadfile>
            <delete file="some.tmp.file" />
        </target>
    
        <target name="all" depends="zip, createManifest">
            <echo message="$${jars.property} = &quot;${jars.property}&quot;" />
            <echo message="$${mfClasspath} = &quot;${mfClasspath}&quot;" />
        </target>
    </project>
    

    When I executed the above Ant buildfile, the following was output to the console:

    Buildfile: /workspace/StackOverflow/build.xml
    zip:
          [zip] Building zip: /workspace/StackOverflow/example.zip
       [delete] Deleting directory /workspace/StackOverflow/tmp.dir
    createManifest:
       [delete] Deleting: /workspace/StackOverflow/some.tmp.file
    all:
         [echo] ${jars.property} = "lib/Dom4J/dom4j-1.6.1.jar;lib/GSON/gson-2.1.jar;lib/Guava/guava-11.0.2.jar"
         [echo] ${mfClasspath} = "dom4j-1.6.1.jar gson-2.1.jar guava-11.0.2.jar"
    BUILD SUCCESSFUL
    Total time: 675 milliseconds
    

    Also, example.zip contained the following entries:

    • lib/dom4j-1.6.1.jar
    • lib/gson-2.1.jar
    • lib/guava-11.0.2.jar
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use ant for creating .jar files in Eclipse. Works great. I have a
We have inherited an ant build file but now need to deploy to both
I have a codebase that I want to produce several deliverable jar files, each
We have an ant build file that needs to encrypt/decrypt a bunch of files
I have following ant file to build. But unfortunately <project default=build.deploy.start basedir=.> <property name=target.dir
Summary How can you make ant repeatedly generate byte-identical jar files from the same
Hi I'm completly knew to Ant files and makefiles. I have a file structure
I have an ANT configuration file which is becoming complicated, and now I'm stuck
i have the following code snippet in my ANT File which compiles my project
I have an ant target that echo's the content of an eclipse .project file,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.