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,550 points
741 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,320 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,520 points
71 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 in Java by Omkar
• 67,120 points
32 views
0 votes
1 answer

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

I tried doing it this way - java.lang.reflect.Method ...READ MORE

answered Apr 27, 2018 in Java by developer_1
• 3,280 points
42 views
0 votes
2 answers

How can I get the filenames of all files in a folder which may or may not contain duplicates

List<String> results = new ArrayList<String>(); File[] files = ...READ MORE

answered Sep 12, 2018 in Java by Sushmita
• 6,840 points
587 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 parth295
• 4,600 points
58 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 parth295
• 4,600 points
317 views
+1 vote
10 answers

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

You Can Simply follow this step Create ...READ MORE

answered Dec 10, 2018 in Java by Sukesh
15,140 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 in Java by anonymous
1,728 views
0 votes
1 answer

Listing all the subclasses of a specific class in Java

There is a simple library available for ...READ MORE

answered Jun 7, 2018 in Java by geek.erkami
• 2,320 points
124 views
0 votes
1 answer

How to move or copy a file in Java

You can follow the below java.nio operations: public static ...READ MORE

answered Nov 2, 2018 in Java by geek.erkami
• 2,320 points
19 views