Hello all,
I would like, in my Java application, to find the pathname to the .jar file
running. I could not find how to do that in the doc. Can anyone help me?
Thanks, Francois
Stefan Ram - 12 Oct 2007 17:28 GMT
>find the pathname to the .jar file running.
Get the ClassLoader object of the class containing the main
method of the application,
use getSystemResource( classPath ) of this ClassLoader object,
to get an URL object (where »classPath« might look like
"package/ClassName.class"),
use openConnection() to get a java.net.JarURLConnection object
from this and then
use getJarFile() to get a java.util.jar.JarFile object.
Stefan Ram - 12 Oct 2007 17:43 GMT
>use getSystemResource( classPath ) of this ClassLoader object,
>to get an URL object (where »classPath« might look like
>"package/ClassName.class"),
PS: Where classPath is the class containing
the application's main method.
Andrew Thompson - 12 Oct 2007 18:53 GMT
...
>I would like, in my Java application, to find the pathname to the .jar file
>running. ...
Why?

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Piotr Kobzda - 12 Oct 2007 20:24 GMT
> I would like, in my Java application, to find the pathname to the .jar file
> running. I could not find how to do that in the doc. Can anyone help me?
YourMain.class.getProtectionDomain().getCodeSource().getLocation();
piotr
Roedy Green - 13 Oct 2007 06:18 GMT
>I would like, in my Java application, to find the pathname to the .jar file
>running. I could not find how to do that in the doc. Can anyone help me?
see http://mindprod.com/jgloss/wherejars.html#FINDING

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Click - 13 Oct 2007 10:00 GMT
"Roedy Green" <see_website@mindprod.com.invalid> a écrit dans le message de
news: >>I would like, in my Java application, to find the pathname to the
.jar file
>>running. I could not find how to do that in the doc. Can anyone help me?
> see http://mindprod.com/jgloss/wherejars.html#FINDING
Thanks! This worked...
Francois
Andrew Thompson - 13 Oct 2007 10:17 GMT
>"Roedy Green" <see_website@mindprod.com.invalid> a écrit dans le message de
>news: >>I would like, in my Java application, to find the pathname to the
[quoted text clipped - 3 lines]
>
>Thanks! This worked...
It may have achieved the strategy, but what was the goal?
*Why* did you need this location?

Signature
Andrew Thompson
http://www.athompson.info/andrew/