Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get path of the actual running jar

Status
Not open for further replies.

bateman23

Programmer
Mar 2, 2001
145
DE
Hi,
i created an executable jar of my java-prog. The application starts, but i'm getting in trouble when trying to access some files. (html files). I'm using a function getAppPath to retrieve the actual path of the class-file, but apperently this code doesn't work within the jar-archive.
So: how do i get the actual path of the jar-file within java?

Thanx in advance,
Daniel

Here is my getAppPath-Code
Code:
package gui;


import java.net.*;

class getAppPath
{
  public String getAppPath()
   {
     ClassLoader cl = this.getClass().getClassLoader();
     URL u = cl.getResource(".");
     return u.toString();
   }

  public static void main( String[] args )
   {
   }
}

---------------------------------------
Visit me @:
 
Try :

URL loc = this.getClass().getProtectionDomain().getCodeSource().getLocation();
 
No, it also just works in my ide, but not with the jar.
The same with:
Code:
String pfad = System.getProperty("user.dir");

---------------------------------------
Visit me @:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top