Retrieving the path of a running jar file

0 votes

I have a piece of code which runs within the JAR file. Now, I want to check in which file/ folder my JAR files are being executed.

How can I do this? Please guide.

May 25, 2018 in Java by 93.lynn
• 1,620 points
4,375 views

1 answer to this question.

0 votes

Its quite simple. Try using the below code.

return new File(AbcClass.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath();

Just replace the “AbcClass” with your own class name and execute it, to get the desired results. Hope this helps!!

answered May 25, 2018 by geek.erkami
• 2,680 points

Related Questions In Java

0 votes
1 answer

How do I create a Java string from the contents of a file?

If you're looking for an alternative that ...READ MORE

answered Apr 19, 2018 in Java by Rishabh
• 3,580 points
214 views
0 votes
2 answers

What is the meaning of purpose of this command: java -jar <some jar file>.jar ?

JAR (Java Archive) file is a package file ...READ MORE

answered Mar 21, 2019 in Java by Omkar
• 69,040 points
204 views
0 votes
2 answers

How can I invoke a method when the method name is in the form of a given string?

You could probably use method invocation from reflection: Class<?> ...READ MORE

answered Aug 19, 2019 in Java by Sirajul
• 54,020 points
167 views
0 votes
1 answer

How to run the JAR files in windows?

Following are the steps to run the ...READ MORE

answered May 28, 2018 in Java by Parth
• 4,630 points
181 views
0 votes
1 answer

How to run a JAR file in Java?

The command given below will help you ...READ MORE

answered Jun 1, 2018 in Java by Parth
• 4,630 points
2,989 views
+2 votes
11 answers

Unable to execute jar- file: “no main manifest attribute”

add a jar/manifest/attributes setting like this: apply plugin: ...READ MORE

answered Nov 27, 2018 in Java by krishti
76,398 views
0 votes
2 answers

Include all the jars in a directory within the Java classpath

Just use lib/*   not lib/*.jar   That's the ...READ MORE

answered Apr 6, 2019 in Java by anonymous
6,039 views
+2 votes
3 answers

Listing all the subclasses of a specific class in Java

Try with BurningWave core library. Here an ...READ MORE

answered Dec 29, 2019 in Java by anonymous
• 370 points

edited Jan 9 by anonymous 2,251 views
0 votes
2 answers

How to move or copy a file in Java

The new JAVA Specification Request 203 -NIO will ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 54,020 points
94 views