Maven and native libraries

11,617

Solution 1

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).

Solution 2

you can define your native lib like this way

   <dependency>
      <groupId>com.***.</groupId>
      <artifactId>abc.jar</artifactId>
      <version>1.0</version>
      <scope>system</scope>
   <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/abc.jar</systemPath>
   </dependency>
Share:
11,617
EK.
Author by

EK.

Java developer

Updated on June 04, 2022

Comments

  • EK.
    EK. almost 2 years

    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.

  • EK.
    EK. about 14 years
    sorry, i'm newbie in maven, but my project have different structure. what i should to do?
  • Devanshu Mevada
    Devanshu Mevada about 14 years
    @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.
  • EK.
    EK. about 14 years
    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.
    EK. about 14 years
    in my classpath i have environment variable with path to libraries
  • Devanshu Mevada
    Devanshu Mevada about 14 years
    @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).
  • EK.
    EK. about 14 years
    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.
    EK. about 14 years
    maybe it is somthing like LD_LIBRARY_PATH ?
  • Devanshu Mevada
    Devanshu Mevada about 14 years
    @EK You'll find some answers in stackoverflow.com/questions/2410384/… and the various links mentioned in there (stackoverflow.com/questions/1962718/maven-and-the-jogl-libr‌​ary/…, humboldt.co.uk/2009/02/…). 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.
  • marinier
    marinier over 4 years
    The question is about native libs (e.g., .so, .dll, etc.), not system provided jars.