Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ANT Jar blues

 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding the classpath attribute to your manifest.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
webaesthet
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic