Home arrow static arrow Java Programming [Archive] - Directory Inside Jar
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Directory Inside Jar
This topic has 7 replies on 1 page.

Posts:64
Registered: 00-08-07
Directory Inside Jar  
Jul 14, 2003 6:37 PM



 
How do I get the URL of a directory inside my JAR file?
 

Posts:1,126
Registered: 00-02-13
Re: Directory Inside Jar  
Jul 14, 2003 6:45 PM (reply 1 of 7)



 
I explained this before once... hummm

this might help you out.

http://forum.java.sun.com/thread.jsp?forum=31&thread=411338

... you see, zip files don't really have "directories" they just have "entries" ...

There is such a thing as Jar URLs though, they look like this.

jar:file://tmp/jarfile.jar!/mypackage/myclass.class

where that would refer to a class within the jar file, but something like..

jar:file://tmp/jarfile.jar!/somedirectory/

Just doesn't have any useful meaning...

Hope I helped...

-Spinoza
 

Posts:64
Registered: 00-08-07
Re: Directory Inside Jar  
Jul 14, 2003 6:50 PM (reply 2 of 7)



 
Thanks, but it does have a useful meaning for me. I'm building a music thing for my game that will randomly get files out of a directory in the jar. The MusicBox class should not have to know about the titles of the files, but simply the directory they all reside in.
 

Posts:1,126
Registered: 00-02-13
Re: Directory Inside Jar  
Jul 14, 2003 6:55 PM (reply 3 of 7)



 
Like I said... that's just not how a jar/zip file works. There is not "index per directory" to get a list of files. This is all the jar file knows.

/somedir/dir1/somefile1.txt --> [a bunch of bytes]
/somedir/dir1/somefile2.txt --> [a bunch of bytes]

There is no coherence of relation amoung the two files. In order to achieve it you're going to have to walk through all the "entries" in the jar file and build an in memory data structure to reference. This is infact how zip/jar files are extracted. You can then query your data structure for indiviual file URLs and get them as streams when you need them.

-Spinoza
 

Posts:64
Registered: 00-08-07
Re: Directory Inside Jar  
Jul 14, 2003 6:55 PM (reply 4 of 7)



 
Wait, I think your link is trying to say that you HAVE to hard code it?
 

Posts:1
Registered: 7/14/04
Re: Directory Inside Jar  
Jul 14, 2004 11:32 AM (reply 5 of 7)



 
I have a jar file for my applet. Inside this jar are two other jar files (mail.jar and activation.jar). I want to use for my classpath. In the manifest.mf, I can state the classpath, but how would i reference it to mail.jar and activation.jar?
I tried using the way you showed, but this didn't work.

Alex
 

Posts:709
Registered: 5/12/04
Re: Directory Inside Jar  
Jul 14, 2004 11:48 AM (reply 6 of 7)



 
Why not have all 3 jars in the same directory? (main.jar, mail.jar and activation.jar).
 

Posts:709
Registered: 5/12/04
Re: Directory Inside Jar  
Jul 14, 2004 11:51 AM (reply 7 of 7)



 
Thanks, but it does have a useful meaning for me. I'm
building a music thing for my game that will randomly
get files out of a directory in the jar. The MusicBox
class should not have to know about the titles of the
files, but simply the directory they all reside in.

Can't you get the music directory (from the jar) as a URL, and then call <nameOfURL>.getFile()
to get the dirctory as a file? Then get all the directory's contents with file.list(); or file.listFiles(); ??

regards,

lutha
 
This topic has 7 replies on 1 page.