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

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

Use ClassLoader.getResource() to find the URL for your current class.
For example:
```
```
package foo;

public class Test
{
    public static void main(String[] args)
    {
        ClassLoader loader = Test.class.getClassLoader();
        System.out.println(loader.getResource("foo/Test.class"));
    }
}
```
```
(This example taken from
a similar question
.)
To find the directory, you'd then need to take apart the URL manually. See the
JarClassLoader tutorial
for the format of a jar URL.