Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I copy files into an existing JAR with Ant?

Tags:

I have a project that needs to access resources within its own JAR file. When I create the JAR file for the project, I would like to copy a directory into that JAR file (I guess the ZIP equivalent would be "adding" the directory to the existing ZIP file). I only want the copy to happen after the JAR has been created (and I obviously don't want the copy to happen if I clean and delete the JAR file).

Currently the build file looks like this:

<?xml version="1.0" encoding="UTF-8"?> <project name="foobar" basedir=".." default="jar">      <!-- project-specific properties -->     <property name="project.path" value="my/project/dir/foobar" />      <patternset id="project.include">         <include name="${project.path}/**" />     </patternset>     <patternset id="project.jar.include">         <include name="${project.path}/**" />     </patternset>      <import file="common-tasks.xml" />      <property name="jar.file" location="${test.dir}/foobar.jar" />         <property name="manifest.file" location="misc/foobar.manifest" /> </project> 

Some of the build tasks are called from another file (common-tasks.xml), which I can't display here.

like image 542
troyal Avatar asked Feb 05 '09 22:02

troyal


People also ask

Can third party jar files be added to a war file in ant?

So you can include any jar.

What is FileSet in Ant?

A FileSet is a group of files. These files can be found in a directory tree starting in a base directory and are matched by patterns taken from a number of PatternSets and Selectors. PatternSets can be specified as nested <patternset> elements.


1 Answers

<jar update="true"> ... </jar> 
like image 89
OscarRyz Avatar answered Nov 05 '22 23:11

OscarRyz