External library path

425 views
Skip to first unread message

Jeremy Leung

unread,
Jul 14, 2022, 6:46:34 AM7/14/22
to NAR Maven plugin
I have a test code which will load the shared library dynamically (i don't want to link with it);
I've tried to set the scope to runtime for the dependency but it turns out it will linked with it.

Is it possible to set additional path for the test to search for the shared library?


Karsten Spang

unread,
Jul 14, 2022, 10:03:27 AM7/14/22
to NAR Maven plugin
It is doable, but not that simple. You need to set LD_LIBRARY_PATH environment variable. It needs to include your own shareable libraries, those of dependencies, and then where your added library is. I use the following for surefire, because I need to have the Oracle shareable library in my path when I test my JNI project. 

Please note:
  • You need to exclude the variable first, because the Java setenv will not overwrite.
  • This is for a JNI project, the exact path is different for other types of projects.
  • This example does not have other dependencies.
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <excludedEnvironmentVariables>
            <excludedEnvironmentVariable>LD_LIBRARY_PATH</excludedEnvironmentVariable>
          </excludedEnvironmentVariables>
          <environmentVariables>
            <LD_LIBRARY_PATH>${env.ORACLE_HOME}/lib:${project.build.directory}/nar/${project.artifactId}-${project.version}-${nar.aol}-jni/lib/${nar.aol}/jni</LD_LIBRARY_PATH>
          </environmentVariables>
        </configuration>
      </plugin>

Reply all
Reply to author
Forward
0 new messages