🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.language
6 messages
6 total messages Started by Oliver Fri, 20 Oct 2006 11:14
location of jar file
#267
Author: Oliver
Date: Fri, 20 Oct 2006 11:14
23 lines
1717 bytes
Hi,

i have a question concerning the location of the jar file.
In Delphi there is the application object, and the property 
ExeName gives the location of the exe. In Java there is no 
application object. But i still would like to know where the jar
 file is located.

At the moment im using the following approach:
- my installation routine writes an environment variable (content: the path into which the installation writes the jar)
- my program reads this environment variable 

This works, but i do not really like this approach.
What i really would appreciate is an information from the class
 itself (where it is located) - without any foreign info (such 
as environment variable).

At the moment my jar file doesnt know where it is, it needs somebody else to tell him :)

regards

Oliver
Re: location of jar file
#268
Author: Magnus
Date: Fri, 20 Oct 2006 20:23
30 lines
2143 bytes
Oliver wrote:
> Hi,
> 
> i have a question concerning the location of the jar file.
> In Delphi there is the application object, and the property 
> ExeName gives the location of the exe. In Java there is no 
> application object. But i still would like to know where the jar
>  file is located.
> 
> At the moment im using the following approach:
> - my installation routine writes an environment variable (content: the path into which the installation writes the jar)
> - my program reads this environment variable 
> 
> This works, but i do not really like this approach.
> What i really would appreciate is an information from the class
>  itself (where it is located) - without any foreign info (such 
> as environment variable).
> 
> At the moment my jar file doesnt know where it is, it needs somebody else to tell him :)
> 
I'm not sure if this solves the problem but when I run the following:
     Properties prop = new Properties();
     prop = System.getProperties();
     String dir=prop.getProperty("user.dir");
     System.out.println("dir="+dir);

the "user.dir" property display where I run my program

To see all properties:
     prop.list(System.out);
Re: location of jar file
#269
Author: Gillmer J. Derge [TeamB]
Date: Mon, 23 Oct 2006 02:02
21 lines
1868 bytes
Oliver wrote:
> i have a question concerning the location of the jar file.
> In Delphi there is the application object, and the property 
> ExeName gives the location of the exe. In Java there is no 
> application object. But i still would like to know where the jar
>  file is located.

String myClassName = MyClass.getName();
String myClassFileName = myClassName.replace('.', '/') + ".class";
URL whereAmI = MyClass.class.getResource(myClassFileName);

Fix any syntax errors.  I've used this general approach before, but I 
haven't actually compiled or tested the exact code shown above.

If the class is in a JAR file, this will be a JAR URL.  See the 
documentation on java.net.JarURLConnection for more details.  If the 
class file comes from somewhere else (a directory with class files, a 
network URL, etc.) then you would need to handle that differently.

-- 
Gillmer J. Derge [TeamB]
Re: location of jar file
#273
Author: Oliver
Date: Tue, 31 Oct 2006 16:55
10 lines
1057 bytes
Hi

thanks a lot. This works during design time.
I will try it also for a jar file and i will have a look at 
this JAR url class.

friendly greetings

Oliver 
Re: location of jar file
#274
Author: Oliver
Date: Tue, 31 Oct 2006 16:57
10 lines
1057 bytes
Hi

thanks, im just wondering what the difference would be
between your approach and the other approach using the url of
 the main class. Hmm... :)

friendly greetings

Oliver
Re: location of jar file
#275
Author: Magnus
Date: Wed, 01 Nov 2006 22:21
12 lines
1232 bytes
Oliver wrote:
> Hi
> 
> thanks, im just wondering what the difference would be
> between your approach and the other approach using the url of
>  the main class. Hmm... :)
> 
> friendly greetings
> 
> Oliver

I wonder about the same thing. Please keep us posted.
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