Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.5k points)

My code runs inside a JAR file, say foo.jar, and I need to know, in the code, in which folder the running foo.jar is.

So, if foo.jar is in C:\FOO\, I want to get that path no matter what my current working directory is.

1 Answer

0 votes
by (46k points)

The best solution to this problem is to use:

Return new File(NameofClass.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath();

Related questions

0 votes
1 answer
0 votes
1 answer
asked Oct 17, 2019 in Java by Shubham (3.9k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...