🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.api
3 messages
3 total messages Started by Alexei Akimov Wed, 04 Dec 2002 10:45
Jar's path at the runtime
#737
Author: Alexei Akimov
Date: Wed, 04 Dec 2002 10:45
12 lines
1499 bytes
Dear expert,

I have a following question: Let we have a java application packed into jar
file or native executable (using JBuilder). Can the application determine
jar or exe file path at the runtime? Is there an analogue of Win32
GetModuleName in java? When I work with Delphi I store ini (or properties)
files in the same folder where the exe file is stored. I can not pack the
properties files into jar as a resourse because the application needs change
it while running (for example it saves there UI preferences).

Thanks in advance,
Alexei Akimov.
Re: Jar's path at the runtime
#738
Author: Shankar Unni
Date: Wed, 04 Dec 2002 18:07
28 lines
2237 bytes
Alexei Akimov wrote:

> I have a following question: Let we have a java application packed into jar
> file or native executable (using JBuilder). Can the application determine
> jar or exe file path at the runtime? 

There is a near-exact equivalent of GetModuleName (which gives you the 
executable or  DLL that defines an entry point) : you can find out where 
a particular loaded class is located, as follows (if you have an object 
of that class)

   obj.getClass().getProtectionDomain().getCodeSource().getLocation()

This expression returns you a java.net.URL of where obj.getClass() was 
loaded from.  For instance, when I run this in a standalone class file 
in the current directory, I get:

   file:/C:/Shankar/

which means that my "bar.class" was loaded from this directory (it's a 
given that "class bar" is in a file called "bar.class").  Similarly, if 
I shove bar.class into an "xxx.jar", put that in my classpath and 
execute the same program, I get

   file:/C:/Shankar/xxx.jar

--
Shankar.
Re: Jar's path at the runtime
#739
Author: John McGrath TeamB
Date: Wed, 04 Dec 2002 18:28
21 lines
1825 bytes
On Wed, 4 Dec 2002 13:45:04 +0300, Alexei Akimov wrote:

> Let we have a java application packed into jar file or native
> executable (using JBuilder). Can the application determine
> jar or exe file path at the runtime? Is there an analogue of
> Win32 GetModuleName in java? When I work with Delphi I store
> ini (or properties) files in the same folder where the exe
> file is stored. I can not pack the properties files into jar
> as a resourse because the application needs change it while
> running (for example it saves there UI preferences).

http://www.visi.com/~gyles19/fom-serve/cache/391.html

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads