I need to merge a couple jar files into one jar using Ant.
It is easy to do this for a fixed list of jarfiles, using <zipfileset>. The problem is, I want to do this in a generic way, and avoid hard-coding the names of the jar files.
Here is a section of my build file:
I have to specify the dependencies twice: Once for my build classpath, and once in the jar task. It would be nice to use the ${dependencies} property for both. Unfortunately I don't see how to make the <zipfileset> do that.
Thanks Geoffrey
Sun Certified Programmer for the Java 2 Platform
Andy Hahn
Ranch Hand
Joined: Aug 31, 2004
Posts: 225
posted
0
I wouldn't recommend doing this. However to do this, you will have to either hard code the jar names in the mainfest file OR find a neat way to read the jar file names (using java.io) and build up the manifest file.
Geoffrey Falk
Ranch Hand
Joined: Aug 17, 2001
Posts: 171
posted
0
Why don't you recommend doing this? The obvious purpose is just to make a single application file (executable jar) that can run with "java -jar". My program has dependencies on some other jars (all open source). Merging everything into one jar seems to be the simplest way. As long as I obey the open source license, there aren't any legal issues.
I did not put the classpath in the Manifest file. I am not doing anything fancy with classloaders. The only thing I specified in the Manifest is the Main-Class.
Anyways, since I couldn't think of a way to do this using <zipfileset>, now I am expanding all the jars into a temp directory and then jarring it up again. This is a bit slower but it works.
Thanks Geoffrey
Glenn Seg
Greenhorn
Joined: Sep 20, 2005
Posts: 2
posted
0
I see that in your orignal approach (naming each file) and in the new approach, you are omitting the data in the META-INF directory. Actually, in the second way, the contents of the META-INF directory gets overwritten for each jar file that is expanded.
Are you planning to merge the manifest files in a future revision of the build file? In addition to having possible legal problems (dependent on the jar files you are using), you are losing data that may or may not be important. Do you think that not having the manifest information will cause problems?
The reason I ask is that I am doing the same thing and I can't afford for this to cause some unforseen problem.