In looking around and reading other similar posts, I've been unable to solve a problem I've been having with LWJGL as a dependency. I'll try to be as descriptive and informative as possible, so thank you for any responses ahead of time.
Objective: Create a project that depends on LWJGL (Version 2.9.1) in Eclipse(Version: Luna Service Release 1 (4.4.1)) using Maven 2 (M2E 1.5.0 plugin).
So far, I've setup my project in Eclipse as a Maven project using M2E.
I've setup my pom.xml
after reading through various articles/posts that touch on the subject of Eclipse+Maven+LWJGL and it has turned out as such:
<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">
<!-- Supported POM Version -->
<modelVersion>4.0.0</modelVersion>
<!-- Project Information -->
<groupId>HIDDEN.GROUP.ID</groupId>
<artifactId>HIDDEN.ARTIFACT.ID</artifactId>
<version>0.1.0</version>
<name>HIDDEN.NAME</name>
<description>HIDDEN DESCRIPTION</description>
<!-- Build Properties -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lwjgl-version>2.9.1</lwjgl-version>
<main>HIDDEN.MAIN.CLASS</main>
</properties>
<!-- Dependencies -->
<dependencies>
<dependency>
<groupId>org.lwjgl.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>${lwjgl-version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.lwjgl.lwjgl</groupId>
<artifactId>lwjgl_util</artifactId>
<version>${lwjgl-version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<!-- Build Configuration -->
<build>
<finalName>${project.name}</finalName>
<defaultGoal>clean package</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<!-- Resources -->
<resources>
<resource>
<targetPath>.</targetPath>
<directory>${basedir}/src/main/resources/</directory>
<filtering>true</filtering>
<includes>
<!-- Include All HOCON Resources -->
<include>*.config</include>
</includes>
</resource>
</resources>
<!-- Plugins -->
<plugins>
<!-- Maven Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<!-- Maven Shader -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.lwjgl.lwjgl:*</include>
</includes>
</artifactSet>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>${main}</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<!-- Maven Natives -->
<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>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
com.googlecode.mavennatives
</groupId>
<artifactId>
maven-nativedependencies-plugin
</artifactId>
<versionRange>
[0.0.5,)
</versionRange>
<goals>
<goal>copy</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
For various reasons I have hidden certain portions of the above pom.xml
(although it should not effect the diagnosis of my problem- just putting it out there, yes all of the above hidden "fields" are correctly typed and referenced. Although if you believe it may cause a problem, do inform me and I will check once again).
Now, the <pluginManagement>...</pluginManagement>
section was automatically generated by Eclipse when:
Eclipse said (screenshot):
Plugin execution not covered by lifecycle configuration: com.googlecode.mavennatives:maven-nativedependencies-plugin:0.0.6:copy (execution: unpacknatives, phase: generate-resources)
To which I attempted to solve (it seems to have been solved) by clicking:
Eclipse said (screenshot):
Permanently mark goal copy in pom.xml as ignored in Eclipse build
Which then generated the following code in the pom.xml
(as seen above):
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
com.googlecode.mavennatives
</groupId>
<artifactId>
maven-nativedependencies-plugin
</artifactId>
<versionRange>
[0.0.6,)
</versionRange>
<goals>
<goal>copy</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Problem #1:
So here's where I'm at with this. I can use Project > Run As > Maven Build
to build my project (Goals: clean package) to which I get an executable JAR file with lwjgl.jar
's contents, lwjgl_util.jar
's contents, and what look to be like a few native files (screenshot) shaded into the JAR as to create a standalone executable file.
Running it wields a beautifully placed:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
.
Okay, so I am aware that java is not aware of "lwjgl" in the system property java.library.path
. Since LWJGL makes calls to the system property java.library.path
in order to locate the native libraries (as I have read here) I am lead to believe that I must now get the path to the required native libraries for the system running this JAR file into the system property java.library.path
.
I was able to get the JVM to properly run my JAR file with the following command through windows command prompt:
java -Djava.library.path=\exact\path\to\lwjgl-2.9.1\native\windows -jar \exact\path\to\<project-name>\target\<project-name>.jar
This ran nicely. Although, I do not want to have to specify the location of the native files manually. Ideally, what I'm looking for is to have the native files embedded in the JAR (they are partially but I have a feeling they're not all of them), selected at run-time based on the user's operating system, and simply set (suggestions/help on how to do so is very much appreciated). So say, they could be embedded under a folder named "/natives/lwjgl/" inside my JAR.
Problem #2:
This problem is the same as the first, although it is not caused by a compiled JAR, but instead when attempting to run my main class through my IDE (Eclipse).
It causes the same error as above:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
.
Now, here's the difference though. I know a solution to this particular problem, it entails simply going through these quick steps:
Project > Build Path > Configure Build Path...
Click "Libraries" tab...
Locate and select "lwjgl.jar" dependency...
Open it's drop down and select "Native library location: (None)"...
Click "edit"...
Fill in field with the correct URI to the natives folder for LWJGL that corresponds with your OS (in my case it's /natives/windows)
Done!
Although where my problem occurs is because I am using maven as my dependency management tool, the lwjgl.jar
dependency in my Build Path (Libraries) for my project is located under "Maven Dependencies" (screenshot).
This prevents me from setting the URI. It simply does not get set (or just doesn't save). So my question here is, am I doing something wrong? Or must I take another approach due to using maven (m2e plugin)?
Thank you very much for reading and helping me out for either of my problems! I put both in this one post as the second problem is basically the first but just a variation (sorta) so I feel making two posts would be useless. I know this may be a duplicate of many others, but I was unable to find the help that corresponded to my particular situation(s). If you need any details or information in particular that I have left out or that you feel I should elaborate on please just ask and I'll be more than willing to provide.
EDIT #1:
Solved problem #2 by adding the VM arguments "-Djava.library.path=target/natives" to the project's run configuration (screenshot).
Although I still have the issue where the compiled JAR can not be executed (I would like to solve it universally and not specifically for my machine as this is to be distributed to Windows/Mac/Linux consumers in the end).
EDIT #2 (Oct 29th, 2014 - 6:30pm EST):
I've been able to create batch files to run the program, although that is obviously platform dependant and not what I'm going for. Any help on getting the system property set would be much appreciated.