Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven native dependences in Eclipse

I'm trying to get some native dependencies (LWJGL) working smoothly in Eclipse (Juno) with Maven.

Current situation:

  • I'm using the maven-nativedependencies-plugin version 0.0.6. This seems to successfully download and unpack the native libraries to the target/natives subdirectory of my project. Fine so far.
  • I can make the dependencies work by manually adding the target/natives directory in Properties / Java Build Path / Maven Dependencies / Native Library Location / Edit...
  • However this only works temporarily as it doesn't seem that the native library location can be specified anywhere in the pom. In particular, it breaks whenever I do a Maven / Update Project... because the Native Library Location is cleared (presumably by m2e re-configuring the project according to the pom)
  • Whenever the native library location is cleared, I just get the error "java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path"

What is the best way to get this working reliably?

like image 710
mikera Avatar asked Jan 15 '23 19:01

mikera


1 Answers

Try this steps;

  • Go to the run configuration of your java project.
  • Open the Arguments tab and enter "-Djava.library.path=target/natives" into the VM Arguments.

For maven project;

Make sure your pom.xml like this;

      <build>
            <plugins>
                    <plugin>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <version>2.3.2</version>
                            <configuration>
                                    <source>1.5</source>
                                    <target>1.5</target>
                                    <encoding>UTF-8</encoding>
                            </configuration>
                    </plugin>
                    <plugin>
                            <groupId>com.googlecode.mavennatives</groupId>
                            <artifactId>maven-nativedependencies-plugin</artifactId>
                            <version>0.0.6</version>
                            <executions>
                                    <execution>
                                            <id>unpacknatives</id>
                                            <phase>generate-resources</phase>
                                            <goals>
                                                    <goal>copy</goal>
                                            </goals>
                                    </execution>
                            </executions>
                    </plugin>
                    <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-jar-plugin</artifactId>
                            <version>2.3.2</version>
                            <configuration>
                                    <archive>
                                            <manifest>
                                                    <mainClass>${main.class}</mainClass>
                                                    <addClasspath>true</addClasspath>
                                                    <classpathPrefix>lib/</classpathPrefix>
                                            </manifest>
                                    </archive>
                            </configuration>
                    </plugin>
                    <plugin>
                            <artifactId>maven-assembly-plugin</artifactId>
                            <version>2.2.1</version>
                            <executions>
                                    <execution>
                                            <id>bundle-project-sources</id>
                                            <phase>package</phase>
                                            <goals>
                                                    <goal>single</goal>
                                            </goals>
                                            <configuration>
                                                    <descriptors>
                                                            <descriptor>src/META-INF/assembly.xml</descriptor>
                                                    </descriptors>
                                            </configuration>
                                    </execution>
                            </executions>
                    </plugin>
            </plugins>
    </build> 

And then left click on the eclipse project, go to the maven menu and click on "update project configuration". If you are still having problems, in the eclipse console tab, open the maven console and do the "update project configuration" option again

like image 122
Sai Ye Yan Naing Aye Avatar answered Jan 23 '23 21:01

Sai Ye Yan Naing Aye