How to find out the .jar file directory

Possible duplicates:
Where was the java class loaded on the file system? How to get the directory where the jar executable is located?

How can I find out the .jar directory in my program I want to use this directory to create other files in the same directory in which the user will save this .jar file

0
source share
1 answer

I don’t think that you can easily find out where the JAR file is, but you can find out in which directory your program is running:

File cwdFile = new File (".");
String cwd = cwdFile.getAbsolutePath();

This only works if the user actually runs the JAR file from the directory in which it is located:

java -jar MyExectuableJar.jar

If they start it from another directory, for example:

java -jar /usr/bin/java/MyExecutableJar.jar

, .

+1

All Articles