0

I have a maven project and jni4net is one of the dependency and it's running fine in Netbeans. But when i package it into a jar i get the error java.lang.UnsatisfiedLinkError: no jni4net.n-0.8.8.0 in java.library.path. I solved this problem in Netbenas by setting Working directory and VM Options in Project Properties -> Run. Now is there a way to include these configurations while packaging it as jar, or any other solution. Thanks in advance...

Here is my 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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>

      <groupId>com.base</groupId>
      <artifactId>base</artifactId>
      <packaging>jar</packaging>
      <version>1.0-SNAPSHOT</version>

      <name>BASE</name>

      <repositories>
        <repository>
          <id>repo</id>
          <url>file://${project.basedir}/./temp-repo</url>
        </repository>
      </repositories>

      <dependencies> 
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>jni4net</groupId>
            <artifactId>jni4net.j</artifactId>
            <version>0.8.8.0</version>
        </dependency>

        <dependency>
            <groupId>customId</groupId>
            <artifactId>customId</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>3.0.0-beta2</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>3.0.0-beta2</version>
        </dependency>
        <dependency>
           <groupId>org.apache.httpcomponents</groupId>
           <artifactId>httpclient</artifactId>
           <version>4.3.5</version>
       </dependency>
      </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.10</version>
                    <executions>
                        <execution>
                            <id>copy</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>
                                    ${project.build.directory}/lib
                                </outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                                <mainClass>com.mysite.myproject.Main</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.1</version>
                    <executions>
                        <execution>
                            <id>copy-resources</id>
                            <phase>validate</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/lib</outputDirectory>
                                <resources>          
                                    <resource>
                                        <directory>lib</directory>
                                        <!--<filtering>true</filtering>-->
                                    </resource>
                                </resources>              
                            </configuration>            
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
Nazim
  • 209
  • 5
  • 17
  • Netbeans normally just adds all dependencies automatically when you clean & build? – Rabbit Guy Aug 03 '16 at 12:51
  • Thanks for this quicky @rabbit guy, but when i am running my jar with java -jar in command prompt it's giving me the above error... – Nazim Aug 03 '16 at 12:52
  • did you clean and build the project? You should have a `dist` folder in the application folder that Netbeans made and that .jar is what you should be running. The `dist` folder should have an additional folder in it called `lib` that contains all libraries needed to run. – Rabbit Guy Aug 03 '16 at 12:55
  • There is no dist folder in maven project @rabbit guy – Nazim Aug 03 '16 at 12:56
  • Doh... sorry. You are correct. Wasn't even considering that. – Rabbit Guy Aug 03 '16 at 12:58
  • Try opening the jar that maven builds and check 1) tha the library is in the lib folder in the jar, and 2) The lib folder is referenced in the Manifest. – jr593 Aug 03 '16 at 13:20
  • There is no lib folder and no reference of it in Manifest, how to do it, what plugin would i need to do it.@jr593 – Nazim Aug 03 '16 at 13:30
  • Considering your suggestions @jr593 i tried [this](http://stackoverflow.com/a/25116745/4405431) answer, still there is no lib folder in jar but there is an reference for lib in MANIFEST – Nazim Aug 03 '16 at 14:17

0 Answers0