Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Today's Posts

Java - How to get jar file name...

Reply
Thread Tools Search this Thread
Advertisement  
Ad Robot

Old 11-06-2005, 12:54 AM   #1
FrenKy

Posts: n/a
Default How to get jar file name...

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

  Reply With Quote
Old 11-06-2005, 01:00 AM   #2
Benji

Posts: n/a
Default Re: How to get jar file name...

FrenKy, while high on whiteboard markers, wrote:
> 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());

--
Of making better designs there is no end,
and much refactoring wearies the body.
  Reply With Quote
Old 11-06-2005, 01:03 AM   #3
Benji

Posts: n/a
Default Re: How to get jar file name...

FrenKy, while high on whiteboard markers, wrote:
> 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());

--
Of making better designs there is no end,
and much refactoring wearies the body.
  Reply With Quote
Old 11-06-2005, 07:04 AM   #4
Roedy Green

Posts: n/a
Default Re: How to get jar file name...

On 5 Nov 2005 16:54:40 -0800, "FrenKy" <> wrote,
quoted or indirectly quoted someone who said :

>can I dinamicaly get location of that jar?


see http://mindprod.com/jgloss/where.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com/ Java custom programming, consulting and coaching.
  Reply With Quote
Old 11-06-2005, 08:05 AM   #5
Benji

Posts: n/a
Default Re: How to get jar file name...

Roedy Green, while high on whiteboard markers, wrote:
> 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.

--
Of making better designs there is no end,
and much refactoring wearies the body.
  Reply With Quote
Old 11-06-2005, 11:49 AM   #6
FrenKy

Posts: n/a
Default Re: How to get jar file name...

All solutions work like a charm
I went with
File jarFile = new File
(org.classes.main.class.getProtectionDomain()
.getCodeSource().getLocation().toURI());

Thanks all!

Nick

  Reply With Quote
Advertisement  
Ad Robot

Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump