Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Pathname

Thread view: 
Click - 12 Oct 2007 17:15 GMT
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/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.