Assuming your code runs inside a jar file, say javagenious.jar, and If you need to know at run time, that what is the absolute path of the jar file, you can use the below code snippet for achieving it.

<code>

 

package www.javagenious.com;
/**
 
Author: Sandeep Joshi
Website: www.javagenious.com
Classification: How to get path of a jar file in Java
 
**/
 
 
public class JavaJarFile
{
    public static void main(String[] args)
    {
        ClassLoader loader = JavaJarFile.class.getClassLoader();
        System.out.println(loader.getResource("javagenious/DoSomething.class"));
    }
}
 
</code>
 
There can be different ways to do this. Some of the other references which can be used are:
 
 
 

 


Enter your email address:

Delivered by FeedBurner



Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)