Install java.library.path for testing

One of the tests uses its own library:

System.loadLibrary("mylib");

libmylib.sois in /usr/local/lib, so I am adding this directory to the VM configuration parameters:-Djava.library.path=/usr/local/lib

However, when I run the tests with Maven, this line calls UnsatisfiedLinkError:

no mylibinjava.library.path

Java is called without this option:

/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

Printing System.getProperty("java.library.path")when an exception is detected gives /opt/idea/bin::/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib. Apparently, the VM parameters from the startup configuration do not affect maven tasks.

So, I tried to set the library path in the VM parameters for the Maven parameters: Settings-> Build, Execution, Deployment-> Build Tools-> Maven-> Runner-> VM. This parameter affects the java call command:

/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

Java , , System.getProperty("java.library.path") !

java.library.path , Maven?

+4
4

Sachin Handiekar, LD_LIBRARY_PATH , Idea. ( Idea - .)

0

maven-surefire-plugin, systemPropertyVariables:

<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.19.1</version>
  <configuration>
    <systemPropertyVariables>
      <propertyName>java.library.path</propertyName>
      <buildDirectory>/usr/local/lib</buildDirectory>
    </systemPropertyVariables>
  </configuration>
</plugin>

java.library.path . , , , .

+2

, , Maven, surefire failafe, JVM , . , , , "java.library.path" , . "systemPropertyVariables", , , . , :

        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.19</version>
            <executions>
                <execution>
                    <id>my-external-tests</id>
                    <goals>
                        ...
                    </goals>
                    <configuration>
                        <argLine>-Djava.library.path=/usr/local/lib</argLine>
                        <groups>com.myCompany.ExternalTest</groups>
                        <includes>
                            <include>**/*Suite.java</include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
        </plugin>
+1

" , Maven Intellij":

, , JVM.

java.library.path System.out Junit .

Mac :

/Users/gareth/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.

, JVM (/Users/gareth/Library/Java/Extensions), jnilib :

:

$ mkdir -p /Users/gareth/Library/Java/Extensions

$ cd /Users/gareth/Library/Java/Extensions

$ ln -s /Users/gareth/Applications/IBM/ILOG/CPLEX_Studio_Community127/cplex/bin/x86-64_osx/libcplex1270.jnilib libcplex1270.jnilib

" ", , " " IDE.

unit test Intellij, maven.

0
source

Source: https://habr.com/ru/post/1628528/


All Articles