• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

merge multiple jars into one jar?

 
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 171
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://one-jar.sourceforge.net/

This achieves what you specified as your aim. As to how you can do it in ant generically...

Well, you could wrap the ant build in a shell script and do.


And then do something with the foreach task from ant-contrib. Or keeping it all anty you just write your own task to do it. For instance :-



Compile errors are yours to fix
[ September 21, 2005: Message edited by: Lewin Chan ]
 
Glenn Seg
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks...I will take a look at the link you posted. Also, there is a 'Manifest' class in the Ant jar file that has a merge method.
 
I'm sure glad that he's gone. Now I can read this tiny ad in peace!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic