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