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 / November 2005

Tip: Looking for answers? Try searching our database.

How to get jar file name...

Thread view: 
FrenKy - 06 Nov 2005 01:54 GMT
Hello..
I have a simple question if someone may know the answer....

If I run some java program from jar file, can I get phisical location
of that jar file dinamicly?

I mean if I have main class let's say:
"org.classes.main"
packed into "C:\jarfile.jar" (or "/usr/home/me/jarfile.jar" :) )

can I dinamicaly get location of that jar?

I want to use it as an resource, but don't want to be bind to single
jar name...

Thanks,
FrenKy
Benji - 06 Nov 2005 01:00 GMT
> Hello..
> I have a simple question if someone may know the answer....

> If I run some java program from jar file, can I get phisical location
> of that jar file dinamicly?

> I mean if I have main class let's say:
> "org.classes.main"
> packed into "C:\jarfile.jar" (or "/usr/home/me/jarfile.jar" :) )

> can I dinamicaly get location of that jar?

> I want to use it as an resource, but don't want to be bind to single
> jar name...

File moduleFile = new File
    (YOURCLASSHERE.class.getProtectionDomain()
    .getCodeSource().getLocation().toURI());

Signature

Of making better designs there is no end,
 and much refactoring wearies the body.

Benji - 06 Nov 2005 01:03 GMT
> Hello..
> I have a simple question if someone may know the answer....

> If I run some java program from jar file, can I get phisical location
> of that jar file dinamicly?

> I mean if I have main class let's say:
> "org.classes.main"
> packed into "C:\jarfile.jar" (or "/usr/home/me/jarfile.jar" :) )

> can I dinamicaly get location of that jar?

> I want to use it as an resource, but don't want to be bind to single
> jar name...

File jarFile = new File
    (org.classes.main.class.getProtectionDomain()
    .getCodeSource().getLocation().toURI());

Signature

Of making better designs there is no end,
 and much refactoring wearies the body.

Roedy Green - 06 Nov 2005 07:04 GMT
>can I dinamicaly get location of that jar?

see http://mindprod.com/jgloss/where.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Benji - 06 Nov 2005 08:05 GMT
> see http://mindprod.com/jgloss/where.html

You should take me out of your killfile so you don't reply to questions
that I've already answered.  ;-)

Signature

Of making better designs there is no end,
 and much refactoring wearies the body.

FrenKy - 06 Nov 2005 11:49 GMT
All solutions work like a charm :)
I went with
File jarFile = new File
       (org.classes.main.class.getProtectionDomain()
       .getCodeSource().getLocation().toURI());

Thanks all!

Nick


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.