This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes getting the name of a jar file from inside the jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getting the name of a jar file from inside the jar" Watch "getting the name of a jar file from inside the jar" New topic
Author

getting the name of a jar file from inside the jar

Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
I have a jar. This jar has code in it similar to this:

studyJar is a JarFile representation of the jar this code is executing in. I get studyID and studyVersion from a text file located inside the jar.
I need to add the functionality where the jar can be renamed by end users.
Is it possible for code inside of a jar to get the name of the jar it resides in? I need its name to instantiate the JarFile above.
Thanks,
[ March 28, 2002: Message edited by: Jason Kretzer ]

Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
If you do not believe it to be possible at least tell me that. I don't want to waste my time looking for something that is not there.
Thanks,
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
This is one solution. It's painful. I hope there is a better way, but I don't know one.
Grrr. HTML is not enabled.

[ March 28, 2002: Message edited by: David Weitzman ]
Ivor Horton
Author
Ranch Hand

Joined: Mar 22, 2002
Posts: 67
Jason,
I haven't tried it but if you have the JarFile object, the getName() method that is inherited from java.util.ZipFile might help.


Ivor Horton<br />Author of the Beginning Java Series including the new <a href="http://www.amazon.com/exec/obidos/ASIN/1861005695/ref=ase_electricporkchop" target="_blank" rel="nofollow">Beginning Java 2 SDK 1.4 Edition</a>
Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
No, I need the name of the jar to instantiate the JarFile object to begin with.
Thanks though,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting the name of a jar file from inside the jar