Set java.library.path for testing
<p>One of the tests uses a native library:</p>

<pre><code>System.loadLibrary("mylib");
</code></pre>

<p><code>libmylib.so</code> is located in <code>/usr/local/lib</code>, So I add this directory in configuration VM options: <code>-Djava.library.path=/usr/local/lib</code></p>

<p>However, when I run tests with Maven, this line throws <code>UnsatisfiedLinkError</code>:</p>

<blockquote>
  <p>no <code>mylib</code> in <code>java.library.path</code></p>
</blockquote>

<p>Java is invoked without this option:</p>

<pre><code>/usr/lib/jvm/java-8-oracle/bin/java -Dmaven.home=/opt/idea/plugins/maven/lib/maven3 -Dclassworlds.conf=/opt/idea/plugins/maven/lib/maven3/bin/m2.conf -Didea.launcher.port=7538 -Didea.launcher.bin.path=/opt/idea/bin -Dfile.encoding=UTF-8 -classpath /opt/idea/plugins/maven/lib/maven3/boot/plexus-classworlds-2.4.jar:/opt/idea/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=15.0.3 test
</code></pre>

<p>Printing <code>System.getProperty("java.library.path")</code> when catching the exception gives <code>/opt/idea/bin::/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib</code>. Apparently VM options from run configuration have no effect on maven tasks. </p>

<p>So I tried to set library path in VM options for Maven: <em>Settings->Build, Execution, Deployment->Build Tools->Maven->Runner->VM options</em>. This option has the effect on java invocation command:</p>

<pre><code>/usr/lib/jvm/java-8-oracle/bin/java -Djava.library.path=/usr/local/lib -Dmaven.home=/opt/idea/plugins/maven/lib/maven3 -Dclassworlds.conf=/opt/idea/plugins/maven/lib/maven3/bin/m2.conf -Didea.launcher.port=7539 -Didea.launcher.bin.path=/opt/idea/bin -Dfile.encoding=UTF-8 -classpath /opt/idea/plugins/maven/lib/maven3/boot/plexus-classworlds-2.4.jar:/opt/idea/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=15.0.3 test
</code></pre>

<p>But even though Java is now invoked with this option, it still fails to load the library, and <code>System.getProperty("java.library.path")</code> still contains the same thing!</p>

<p>How to set <code>java.library.path</code> for tests invoked with Maven?</p>