Home arrow static arrow Java Programming [Archive] - recursive jar class loader?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - recursive jar class loader?
This topic has 4 replies on 1 page.

Posts:2,562
Registered: 6/7/02
recursive jar class loader?  
Nov 12, 2003 4:15 AM



 
hi,

i'd like to package some jars within a jar since its a very easy way to deploy. Additionally i think legally i'm constrained not to merge them at build time since this would constitute altering some third party IP included.

i've been trying to write a recursive jar class loader this morning that would take an initial jar file, and make its classes available to the jvm. Additionally any jar files found within the original jar file would have an instance of the same class loader i'm writing to deal with there contents - so the whole jar tree is flattened. I'm not concerned with name clashes or anything at this point.

the first approach was to use URL's but jar URL's don't seem to support jars embedded within jars?

the second approach was to use inputstreams but is going to make implementing findResource more difficult since there isn't any URL that can be returned

is there some other way to do this?

any help appreciated,
thanks,
asjf
 

Posts:4,906
Registered: 23/07/02
Re: recursive jar class loader?  
Nov 12, 2003 5:11 AM (reply 1 of 4)



 
You could extract the nested jars to the temp directory using File.createTempFile. It's not a great solution, I admit.
 

Posts:1
Registered: 7/13/04
Re: recursive jar class loader?  
Jul 13, 2004 2:22 AM (reply 2 of 4)



 
Implementing getClass/getResourceAsStream to support embedded jars is straightforward, just remember that available() doesn't work for archive entries inside another archive -> the data will need to be read one byte at a time!.

However, supporting getResource will be another matter - you'll have to override the standard jar protocol handler. I haven't tried it yet but will have to very soon I think! There's a good tutorial on this site....
 

Posts:4,496
Registered: 19/06/02
Re: recursive jar class loader?  
Jul 13, 2004 2:28 AM (reply 3 of 4)



 
Never used this, but ...

http://www.yagga.net/java/metajar/
 

Posts:31,095
Registered: 4/30/99
Re: recursive jar class loader?  
Jul 13, 2004 8:27 AM (reply 4 of 4)



 
Instead of doing that, why don't you just deploy them as separate jar files with one of them being an executable jar file whose manifest names the others as being in its classpath? That's just as easy, it's the way it's supposed to be done, and you don't have to spend unproductive time writing classloaders.
 
This topic has 4 replies on 1 page.