Using LWJGL with maven

Started by msacco, June 25, 2018, 20:08:17

Previous topic - Next topic

msacco

Hey, Im not quite sure about using maven with LWJGL, many information resources are very old, but Im just not quite sure, does the official lwjgl download page maven includes the natives? Because I tried making a new project with maven and it simply didn't work giving me an error and Im not sure if its because Im doing something wrong, or its because of the natives, when I googled some people said that my error is because of the natives, but some of those threads were very old, and it seems like there is natives in the maven.

I've downloaded the following maven from the official site:

<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">
	<modelVersion>4.0.0</modelVersion>
	<groupId>SolarSystem</groupId>
	<artifactId>SolarSystem</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<properties>
		<lwjgl.version>3.1.6</lwjgl.version>
		<joml.version>1.9.9</joml.version>
		<lwjgl.natives>natives-windows</lwjgl.natives>
		<groupId>test</groupId>
		<artifactId>test</artifactId>
		<version>1</version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-assimp</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-bgfx</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-egl</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-glfw</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-jawt</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-jemalloc</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-lmdb</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-lz4</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-nanovg</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-nfd</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-nuklear</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-odbc</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-openal</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-opencl</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-opengl</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-opengles</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-openvr</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-ovr</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-par</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-remotery</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-rpmalloc</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-sse</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-stb</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-tinyexr</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-tinyfd</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-tootle</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-vulkan</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-xxhash</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-yoga</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-zstd</artifactId>
			<version>${lwjgl.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-assimp</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-bgfx</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-glfw</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-jemalloc</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-lmdb</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-lz4</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-nanovg</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-nfd</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-nuklear</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-openal</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-opengl</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-opengles</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-openvr</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-ovr</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-par</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-remotery</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-rpmalloc</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-sse</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-stb</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-tinyexr</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-tinyfd</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-tootle</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-xxhash</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-yoga</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.lwjgl</groupId>
			<artifactId>lwjgl-zstd</artifactId>
			<version>${lwjgl.version}</version>
			<classifier>${lwjgl.natives}</classifier>
		</dependency>
		<dependency>
			<groupId>org.joml</groupId>
			<artifactId>joml</artifactId>
			<version>${joml.version}</version>
		</dependency>
		<dependency>
			<groupId>org.lwjgl.lwjgl</groupId>
			<artifactId>lwjgl_util</artifactId>
			<version>2.9.1</version>
		</dependency>
		<dependency>
			<groupId>org.slick2d</groupId>
			<artifactId>slick2d-core</artifactId>
			<version>1.0.2</version>
		</dependency>
	</dependencies>

</project>


I also tried adding this:

<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>

			<plugin>
				<groupId>com.googlecode.mavennatives</groupId>
				<artifactId>maven-nativedependencies-plugin</artifactId>
				<version>${natives.version}</version>
				<executions>
				</executions>
			</plugin>
		</plugins>
	</build>


But it still didn't work, that is my main class btw:

package com.opengl.main;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

public class Main {
	public static void main(String[] args) {
		initDisplay();
		gameLoop();
	}
	
	public static void initDisplay() {
		try {
			Display.setDisplayMode(new DisplayMode(1200, 1200/8*5));
			Display.create();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void gameLoop() {
		while(!Display.isCloseRequested()) {
			Display.sync(144);
			Display.update();
		}
		Display.destroy();
	}
}


Any ideas what am I doing wrong? Thanks for the help :)

KaiHH

slick2d-core and lwjgl_util are not compatible with LWJGL3.
Also, LWJGL3 requires Java 1.8, so change source and target versions of the compiler plugin to at least 1.8.
It is always a good idea to tell us what exactly does not work and what exact error message you are getting, instead of just saying "But it still didn't work".

You can also have a look at https://github.com/LWJGL/lwjgl3-demos/blob/master/pom.xml for a working configuration.

msacco

Quote from: KaiHH on June 25, 2018, 20:19:34
slick2d-core and lwjgl_util are not compatible with LWJGL3.
Also, LWJGL3 requires Java 1.8, so change source and target versions of the compiler plugin to at least 1.8.
It is always a good idea to tell us what exactly does not work and what exact error message you are getting, instead of just saying "But it still didn't work".

You can also have a look at https://github.com/LWJGL/lwjgl3-demos/blob/master/pom.xml for a working configuration.

Oh shiet I was sure I added that as well :x sorry about that, that is the error Im getting:
Exception in thread "main" java.lang.ExceptionInInitializerError
	at org.lwjgl.Sys.createImplementation(Sys.java:124)
	at org.lwjgl.Sys.<clinit>(Sys.java:111)
	at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
	at Main.initDisplay(Main.java:12)
	at Main.main(Main.java:6)
Caused by: java.lang.SecurityException: sealing violation: package org.lwjgl is sealed
	at java.base/jdk.internal.loader.BuiltinClassLoader.getAndVerifyPackage(BuiltinClassLoader.java:845)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineOrCheckPackage(BuiltinClassLoader.java:816)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.defineOrCheckPackage(ClassLoaders.java:218)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:788)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:699)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:622)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
	at org.lwjgl.LWJGLUtil.loadIcon(LWJGLUtil.java:285)
	at org.lwjgl.LWJGLUtil.<clinit>(LWJGLUtil.java:259)
	... 5 more


Im using java 1.9, so I assume that by "at least 1.8" it should run just well, and I just got everything from the official site maven's source, so its weird that jwjgl util is not compatiable with LWJGL 3, I added the slick2d tho, I wanted slick utils but couldn't find maven for that. I'll also try using the pom you sent in the git demo. Thanks.

update - I tried using the maven from the git, but its still not working for a reason..same error.

KaiHH

Quote from: msacco on June 25, 2018, 20:46:51
I just got everything from the official site maven's source, so its weird that jwjgl util is not compatiable with LWJGL 3
Can you post the link here? The "official" site to generate the Maven pom.xml is https://www.lwjgl.org/customize and that surely does not generate any dependency to lwjgl_util.

Also, you are obviously trying to bootstrap a LWJGL 2 application with its Display class. Don't do that. Do not mix LWJGL2 classes/jars with LWJGL3 classes/jars. It will not work. LWJGL3 is using GLFW to manage the windows and OpenGL contexts.

msacco

Quote from: KaiHH on June 25, 2018, 20:54:15
Quote from: msacco on June 25, 2018, 20:46:51
I just got everything from the official site maven's source, so its weird that jwjgl util is not compatiable with LWJGL 3
Can you post the link here? The "official" site to generate the Maven pom.xml is https://www.lwjgl.org/customize and that surely does not generate any dependency to lwjgl_util.

Also, you are obviously trying to bootstrap a LWJGL 2 application with its Display class. Don't do that. Do not mix LWJGL2 classes/jars with LWJGL3 classes/jars. It will not work. LWJGL3 is using GLFW to manage the windows and OpenGL contexts.

I had no idea really, but that worked for me so far, it still works when Im setting up a project manually without maven, but that might have something to do with it.

KaiHH

Then your classpath of the Eclipse project without Maven is not identical with what you declared in your pom.xml as dependencies.
If you manually assemble all those dependencies declared in the pom.xml and put them in your Eclipse Build Path, you'll see that it also does not work.
What Maven (or rather the m2e integration of Maven into Eclipse) does, is to auto-generate the Build/Class Path of the Eclipse project based on the resolved dependencies specified in the pom.xml.

msacco

Quote from: KaiHH on June 25, 2018, 21:11:59
Then your classpath of the Eclipse project without Maven is not identical with what you declared in your pom.xml as dependencies.
If you manually assemble all those dependencies declared in the pom.xml and put them in your Eclipse Build Path, you'll see that it also does not work.
What Maven (or rather the m2e integration of Maven into Eclipse) does, is to auto-generate the Build/Class Path of the Eclipse project based on the resolved dependencies specified in the pom.xml.

*Actually, its not where the error is thrown, because the exceptions are not the same, but thats the last source before the error, so that probably has something to do with it.
Regardless of that, Im pretty sure the problem is something with the natives, as going to where the exception is being thrown there is the next method:

private static SysImplementation createImplementation() {
		switch (LWJGLUtil.getPlatform()) {
			case LWJGLUtil.PLATFORM_LINUX:
				return new LinuxSysImplementation();
			case LWJGLUtil.PLATFORM_WINDOWS:
				return new WindowsSysImplementation();
			case LWJGLUtil.PLATFORM_MACOSX:
				return new MacOSXSysImplementation();
			default:
				throw new IllegalStateException("Unsupported platform");
		}
	}


I don't really know what it does, but I can assume it determines what platform you're on, since something is wrong with the natives, the method can't get the platform, and then throws that error. Might be wrong, but that seems like the most reasonable thing I can think of.

KaiHH

And I can assure you that the problem is 100% NOT the natives. It is that you are using both LWJGL 2 and 3 jars. The jar is marked as sealed, so no other jar can contribute to the package. Both 2 and 3 are trying to do that and that's the error you are getting. Read the exception message.

msacco

Quote from: KaiHH on June 25, 2018, 21:24:50
And I can assure you that the problem is 100% NOT the natives. It is that you are using both LWJGL 2 and 3 jars. The jar is marked as sealed, so no other jar can contribute to the package. Both 2 and 3 are trying to do that and that's the error you are getting. Read the exception message.

I got all my folders totally messed up, and up until now thought I was using the LWJGL 3 jar and just using old LWJGL/opengl commands, so yeah I just really f*cked that up, sorry about that, and thanks again for saving me :] Time to learn new opengl.