4

I'm having a problem with trying to get Maven to load my native library. Currently, I placed my library file (.so) in src/main/resources/ and it gives me an error of it cannot be found in java.library.path. I also tried to place this in my base directory of the project, but gives me the same results.

Below is the maven plugin I tried, but it doesn't seem to work.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
      <systemProperties>
        <property>
          <name>java.library.path</name>
          <value>${project.build.directory}</value>
        </property>
      </systemProperties>
    </configuration>
  </plugin>

If it helps, I run my project directly from Eclipse. I know how to get it to work in Eclipse but want it to work with maven.

@EDIT I also tried running it on the command line and I still receive the same mistakes

Hank
  • 3,367
  • 10
  • 48
  • 86
  • I understand that the `${project.build.directory}` point to `${basedir}/target`. You've mentioned that the `.so` is placed at `src/main/resources` which will be copied to `${project.build.directory}/classes` (`${basedir}/target/classes`). – Charlee Chitsuk Mar 27 '13 at 00:39
  • But when I look in the jar it's at the base – Hank Mar 27 '13 at 01:06
  • Yes, you're correct. The produced jar file contains that resource at the base level. But the surefire executes before that. The phase test comes before phase package. Please refer to http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html – Charlee Chitsuk Mar 27 '13 at 01:10
  • Is there any way to point to the one in the jar? or a folder in the jar, say lib/? – Hank Mar 27 '13 at 01:12
  • I only used to point to the full path to dll/so and understand that it is not possible to point to the jar file. Please see http://stackoverflow.com/questions/4691095/java-loading-dlls-by-a-relative-path-and-hide-them-inside-a-jar/4691879#4691879 – Charlee Chitsuk Mar 27 '13 at 01:24

1 Answers1

3

I did the following in my project:

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
        <argLine>-Djava.library.path=/path/to/your/libs:${java.library.path}</argLine>
        </configuration>
    </plugin>
</plugins>

And it worked for me that way.

Amr
  • 2,420
  • 2
  • 17
  • 26