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
7,753 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,620 points
434 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,150 points
701 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
• 59,090 points
750 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
406 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
5,434 views
+2 votes
13 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
145,787 views
0 votes
1 answer

Can't execute jar- file: “no main manifest attribute”

First, it's kind of weird, to see ...READ MORE

answered Dec 23, 2020 in Java by Gitika
• 65,930 points
790 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
• 460 points

edited Jan 9, 2020 by anonymous 5,620 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
• 59,090 points
179 views