4

I use maven in my java project, and I don't understand how to add in native libraries. In my non-maven project I did it via CLASSPATH. I use NetBeans and maven in my current java project.

fvrghl
  • 3,642
  • 5
  • 28
  • 36
EK.
  • 2,890
  • 9
  • 36
  • 49

1 Answers1

5

If you just want to add the native libraries to the class path, try to put them in src/main/resources.

Update: You can specify where resources exist in the POM:

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <build>
    ...
    <resources>
      <resource>
        <filtering>false</filtering>
        <directory>${basedir}/src/main/native</directory>
        <includes>
          <include>native.so</include>
        </includes>
      </resource>
    </resources>
    <testResources>
      ...
    </testResources>
    ...
  </build>
</project>

But honestly, if you decide to use Maven, you should adopt Maven's standard layout (or you'll have to configure every plugin for your custom layout which is more a source of problems than benefits).

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • sorry, i'm newbie in maven, but my project have different structure. what i should to do? – EK. Mar 15 '10 at 16:39
  • @EK Either put the native libraries in the directory you defined as `` or add details to your question (like your POM and project structure) so that I can provide more guidance. – Pascal Thivent Mar 15 '10 at 16:48
  • my project structure very simple. only one folder /src/ (and test, bin, config,target, lib). what i should change in pom, to said maven use resource folder with libs. this is most interesting part of my pom, i think src test THANKS! – EK. Mar 15 '10 at 17:03
  • in my classpath i have environment variable with path to libraries – EK. Mar 15 '10 at 17:14
  • @EK This is not how things work in Maven and, actually, a JNI project is really not the easiest way to start with Maven. Maybe you should stick with Ant here (especially if you don't want to follow maven's principles and conventions). – Pascal Thivent Mar 15 '10 at 17:24
  • i did next src test resources *.so but when i run project, it is not see libs. all libs in folder resources – EK. Mar 15 '10 at 17:27
  • maybe it is somthing like LD_LIBRARY_PATH ? – EK. Mar 15 '10 at 17:34
  • 1
    @EK You'll find some answers in http://stackoverflow.com/questions/2410384/managing-native-libraries-with-maven and the various links mentioned in there (http://stackoverflow.com/questions/1962718/maven-and-the-jogl-library/1969077#1969077, http://www.humboldt.co.uk/2009/02/wrapping-a-native-library-with-maven.html). As I said, JNI isn't an easy topic and analyzing snippets posted in a 600 chars box isn't really possible. Moreover, your problem is kinda hard to reproduce so I'm sorry but I can't help more. – Pascal Thivent Mar 15 '10 at 18:02