[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting the name of a jar



Jason,

I normally use the "getResource" or "getResourceAsStream" method to read configuration files and other data files that I store in jar files.   This will search for the file name using anything in your CLASSPATH including any jar's included in your CLASSPATH.  It will not guarantee reading from a particular jar if you have multiple jars in your CLASSPATH or directories in your CLASSPATH which contain the same file.  In that case, the first one found will be used.

Cynthia Jeness

"Jason R. Kretzer" wrote:

Hello everyone, I have a jar that needs to perform an operation on itself(like read a text file inside itself).  This is easy enough, however, here is the catch.  How can a jar determine what its own file name is?  This will need to be determined at runtime. eg. 1.) foo.jar is created using the JDK jar tool.
2.) John Q. User renames the jar to bar.jar.
3.) When executed, bar.jar knows its name is "bar.jar" and sets up a connection to do its operation.  
Question:  How can I get bar.jar to know what its name is at runtime? Thanks,-Jason ************************************************************************************
Jason R. Kretzer
Software Engineer
Opinion One
Email:  jason@opone.com
Phone:  (513) 361-2771
Website:  http://alia.iwarp.com "Make visible what, without you, might perhaps never have been seen."
--Robert Bresson
************************************************************************************