Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can you jar jar files?

 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
gautam shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Ross:
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??

i think "Class-Path" attribute in the manifest.mf is for u. and if i am not wrong u had already wrote Main-Class attribute their for executing that jar by double clicking on that.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea, I tried adding all the inner-jars on the Manifest's classpath, but they're still not visible.
They're only visible when the inner-jars are *external* to the executable jar file, and I have them listed in the executable jar's Manifest file.
It seems that nesting jars just isn't something that works.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to unjar the outer jar before you can execute the inner jar.
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if it can be done neatly with java configuration options, but you can always count on the trusty URLClassLoader.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Ross:
Yea, I tried adding all the inner-jars on the Manifest's classpath, but they're still not visible.

How did you specify this? Did you try the jar-protocol in the url? It's pure speculation of mine, but perhaps something like "jar://myjar.jar/..." would work?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic