views:

184

answers:

1

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

+1  A: 

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"&gt;
  <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
sorry, i'm newbie in maven, but my project have different structure. what i should to do?
EK
@EK Either put the native libraries in the directory you defined as `<resource>` or add details to your question (like your POM and project structure) so that I can provide more guidance.
Pascal Thivent
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<build> <sourceDirectory>src</sourceDirectory> <testSourceDirectory>test</testSourceDirectory> <plugins>THANKS!
EK
in my classpath i have environment variable with path to libraries
EK
@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
i did next<build> <sourceDirectory>src</sourceDirectory> <testSourceDirectory>test</testSourceDirectory> <resources> <resource> <directory> resources </directory> <includes> <include>*.so</include> </includes> </resource> </resources> <plugins>but when i run project, it is not see libs. all libs in folder resources
EK
maybe it is somthing like LD_LIBRARY_PATH ?
EK
thx, i think about it
EK
@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