aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant, JAR files, and the associated 'Paths' created in the JAR file - help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant, JAR files, and the associated Watch "Ant, JAR files, and the associated New topic
Author

Ant, JAR files, and the associated 'Paths' created in the JAR file - help!

Vincent Marlow
Greenhorn

Joined: Apr 16, 2004
Posts: 1
I have a relatively simple build.xml file (see below) that simply peruses my local SRC directory and builds a JAR file with the Java class files.
However, when I view the JAR file contents, there are no PATH values associated with any of the class files but I need the package name (which is the same directory structure as my SRC value) listed in the PATH attribute.
How can I use Ant to add the proper package name / directory structure to the Zipped JAR file that build.xml creates?
ANY assistance is appreciated - thanks!
<project name="MyProject" default="dist" basedir=".">
<property name = "src" location = "./cm"/>
<property name = "build" location = "build"/>
<property name = "dist" location="dist"/>

<target name="init">
<tstamp/>
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${src}"/>
</target>

<target name="dist" depends="compile">
<mkdir dir="./lib"/>
<jar jarfile="./lib/MyJar.jar"
basedir="cm/"
/>
</target>

<target name="clean" >
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>

</project>
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, Vincent!
However, when I view the JAR file contents, there are no PATH values associated with any of the class files but I need the package name (which is the same directory structure as my SRC value) listed in the PATH attribute.
I'm not exactly sure what you mean with this. What's the PATH attribute?
The directories used throughout your build.xml file don't match.
In your compile target, I'd recommend that for the destdir you use the ${build} directory. The compile target should then properly place the compiled class files in the ${build} directory in the proper subdirectories matching the packages declared in the source code.
Then, in your jar (or dist) target, I'd recommend something like the following.

This should get your jar file properly built and placed in the ${dist} directory.
(Of course, this all assumes that the source code compiles properly.)
Also, note that in your init target, you'll perhaps want to create the ${dist} directory.
If you're still stuck, do feel free to post more questions. You also might like to read Thomas Paul's introductory Ant article in the March 2002 JavaRanch Journal.
[ April 19, 2004: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
chughead,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Concerning your question, note that when you specify a fileset, you can specify to include and exclude things inside the base directory. Perhaps you'd appreciate reading about my recent adventures of excluding things.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ant, JAR files, and the associated 'Paths' created in the JAR file - help!