This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes ANT Jar blues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "ANT Jar blues" Watch "ANT Jar blues" New topic
Author

ANT Jar blues

Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
This is more of a Jar question, but since I'm using ANT's jar task to do this maybe someone can help.
Can you jar jars? I mean, if you're building a final deployable, double-clickable jar file, and you want to jar up all your own compiled classes, PLUS all the jar libraries you're using in one jar file, can you do that? When I jar all my classes and jars, I can verifiy in WinZip that they have in fact all been added. And I've added a Manifest so I can double-click the jar file and it launches and starts my Java app.
BUT, the problem is, that my classes don't see *any* of the imbeded jar files. So I don't know #1, if you can jar jar files, or #2, if you can, what you have to do to get your classes to see them...how do you specify a classpath to include jars already inside the main jar file??
Thanks!


Rob
SCJP 1.4
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
Try adding the classpath attribute to your manifest.


Matthew Phillips
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Yes,I've done that. All the jars inside my main jar are included in the manifest classpath. However, none of the nested jars' classes are visible to any of my classes even after doing this.
[ April 06, 2002: Message edited by: Rob Ross ]
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
You could but, you'd have to create your own custom classloader and load it into the outer most jar file.
Your other choices are to
1)unjar the files from the others jars and include them in one jar.
2) create your jar with the appropriate entries for Main-Class and Class-Path with the other jars in the same directory. Create an install class which unpacks the contents of the final jar. Include that class and all jars in another jar. When it is run, it unjars all your jars and makes your project ready to run.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
webaesthet
Greenhorn

Joined: Mar 06, 2001
Posts: 3
I think this is how it works:
Add classpath in the Manifest and change all your code to use <object>.getClass().getResourceAsStream() method, which can load a file from within a jar.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Originally posted by webaesthet:
I think this is how it works:
Add classpath in the Manifest and change all your code to use <object>.getClass().getResourceAsStream() method, which can load a file from within a jar.

Welcome to the JavaRanch! Please adjust your display name to meet
the JavaRanch Naming Policy. You can change it here.
Thanks!
and welcome to the JavaRanch!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ANT Jar blues