Load file from same directory as jar-file
<p>I'm using log4j for my logging purposes. To configure everything, I've made a log4j.xml that is outside of the jar-file. It works great, but gives problems when the jar-file isn't executed from the same directory where the log4j.xml is.</p>

<p>Example: jar-file is in /opt/myapp/test.jar</p>

<pre><code>user@host:/opt/myapp$ java -jar test.jar
</code></pre>

<p>works great, but when I try this:</p>

<pre><code>user@host:~$ java -jar /opt/myapp/test.jar
</code></pre>

<p>I get an error that log4j.xml cannot be found. That's because it is looking for it in my current working directory.</p>

<p>I also have a properties file that I use in my application. This file is in the config/ directory where the jar-file is, so /opt/myapp/config in this example. The same issue like the one above occurs when trying to load the config file.</p>

<p><strong>How can I let Java load a file from the directory where the jar-file is (no matter from where the jar is executed)?</strong></p>

<p>Probably something very easy, but I can't figure it out :(</p>
