Pathname

C

Click

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
 
S

Stefan Ram

Click said:
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.
 
S

Stefan Ram

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.
 
P

Piotr Kobzda

Click said:
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
 
A

Andrew Thompson

Click said:
"Roedy Green" <[email protected]> a écrit dans le message de
>>I would like, in my Java application, to find the pathname to the
.jar file

Thanks! This worked...

It may have achieved the strategy, but what was the goal?
*Why* did you need this location?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top