Reputation: 11
I am compiling and packaging my programme with maven and it compiles and package with out any errors, when I run my jar from the command line UI loads well, however when I press the play button I get an error: "Thread-0" java.lang.NoClassDefFoundError: org/lwjgl/glfw/GLFW at gameGraphics.GraphicsDisplay.init(GraphicsDisplay.java:54).
I am using Eclipse as my IDE and have a maven project. The UI is coded using Swing. UI.png I have made a class called GraphicsDisplay which creates my GLFW window using LWJGL: GLFW window (GrapicksDisplay class) the Graphics display class is called when I press the play button in the UI and runs on a separate thread.
So when I run my programme in eclipse it all works fine.... good When I export my programme using Eclipse export and put my source folders with my runnable it all works fine. When I do a maven clean, compile and package the UI works fine however when I press the play button I get the above error: "Thread-0" java.lang.NoClassDefFoundError: org/lwjgl/glfw/GLFW at gameGraphics.GraphicsDisplay.init(GraphicsDisplay.java:54).
So here is my pom.xml:
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"> 4.0.0
<groupId>nhvdr</groupId>
<artifactId>javaSwingBuild_2D</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>javaSwingBuild_2D</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
<lwjgl.version>3.3.4</lwjgl.version>
<joml.version>1.10.7</joml.version>
<lwjgl3-awt.version>0.1.8</lwjgl3-awt.version>
<steamworks4j.version>1.9.0</steamworks4j.version>
<steamworks4j-server.version>1.9.0</steamworks4j-server.version>
<joml-primitives.version>1.10.0</joml-primitives.version>
<lwjgl.natives>natives-windows</lwjgl.natives>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-bom</artifactId>
<version>${lwjgl.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-glfw</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-opengl</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-opengles</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-stb</artifactId>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-glfw</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-opengl</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-opengles</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-stb</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.joml</groupId>
<artifactId>joml</artifactId>
<version>${joml.version}</version>
</dependency>
<dependency>
<groupId>org.lwjglx</groupId>
<artifactId>lwjgl3-awt</artifactId>
<version>${lwjgl3-awt.version}</version>
</dependency>
<dependency>
<groupId>com.code-disaster.steamworks4j</groupId>
<artifactId>steamworks4j</artifactId>
<version>${steamworks4j.version}</version>
</dependency>
<dependency>
<groupId>com.code-disaster.steamworks4j</groupId>
<artifactId>steamworks4j-server</artifactId>
<version>${steamworks4j-server.version}</version>
</dependency>
<dependency>
<groupId>org.joml</groupId>
<artifactId>joml-primitives</artifactId>
<version>${joml-primitives.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>nhvdr.javaSwingBuild.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
What could I be missing?
Upvotes: 1
Views: 135
Reputation: 93
You got your pom.xml
file mostly correct. It's just failing to build a fat jar. You can see that Maven is producing a skinny jar when opening it with 7zip, since no LWJGL files are included in the archive.
Replace your plugins with these two to build a fat jar:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>nhvdr.javaSwingBuild.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
When you build, two jars will be created. The one labeled [your_jar_name]-jar-with-dependencies.jar
is the fat jar. This solution is based on this StackOverflow thread about building a fat jar with Maven.
Note that the fat jar produced will only be able to run on Windows machines, since you only selected the natives for windows-x64 on the LWJGL customize site. If you want your fat jar to run on every computer, on the LWJGL customize webiste, you have to:
pom.xml
file accordingly.You will not need to update anything under plugins
after making this change.
Upvotes: 0