Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include directory structure in an ant jar file?

Tags:

jar

ant

I am a bit of an ant newbie, and I'm having trouble making a jar correctly. As an example, say I want to make a jar with my StringUtil class. Using the following ant directive, I can create the jar, but the problem is that the directory structure is lost. It simply puts StringUtil.class in the base directory of the jar. How can I correct this ant directive so that StringUtil.class is inside the com/test directory in the jar?

<jar destfile="myjar.jar" >
  <fileset file="${build}/com/test/StringUtil.class"/>
</jar>

Thanks!

like image 339
Markus Avatar asked Dec 13 '08 00:12

Markus


1 Answers

You need to tell Ant to build the jar from the base directory, then tell it to include only the desired file. Like so:

<jar destfile="myjar.jar" >
  <fileset dir="${build}" includes="com/test/StringUtil.class"/>
</jar>

Here's the doc for <fileset> tags.

like image 112
sblundy Avatar answered Oct 13 '22 14:10

sblundy