0

My java game (built using lwjgl and Eclipse) won't run after being exported as a Runnable jar from Eclipse. The program runs fine within Eclipse, and the exported jar has the correct Manifest file format. After executing this Jar, it gave me an error:

C:\Users\7rent\Desktop>java -jar hw.jar

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:73)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:95)
at org.lwjgl.Sys.<clinit>(Sys.java:112)
at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
at org.newdawn.slick.AppGameContainer$1.run(AppGameContainer.java:39)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.AppGameContainer.<clinit>(AppGameContainer.java:36)
at core.SecDef.main(SecDef.java:13)
... 5 more

I then (using Stack overflow answers) used JarSplice to add the lwjgl jar and natives to this Jar. The resulting fatjar gives me this:

C:\Users\7rent\Desktop>java -jar SD.jar

Error: Could not find or load main class core.SecDef

The manifest of the jar contains this: https://i.stack.imgur.com/ccpOH.png

and the inside of the FatJar looks like this: https://i.stack.imgur.com/hVBcD.png

I installed the JRE and JDK today, both latest versions with no configuration done to system variables. The project is set to be in compliance with java 6.

Thanks in advance :)

  • 1
    You cannot use native libraries "as is" inside jar files with most operating systems. You need to extract the library to a normal disk file and then load that. – Thorbjørn Ravn Andersen Apr 16 '17 at 16:30
  • Did you use [JarSplice's Fat Jar Creator](http://ninjacave.com/jarsplice) or Eclipse's runnable jar exporter? I suspect JarSplice would add some magic Java code for extracting the DLLs to disk and loading them from there. – Thomas Fritsch Apr 16 '17 at 16:48
  • I used the runnable jar exporter first, then added the natives to that jar with JarSplice. – Trent Stevens Apr 16 '17 at 17:16
  • Don't add third-party libraries to your JARs! Distribute them _with_ your JARs in subdirectories identified in the manifest `Class-Path`. https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html – Lew Bloch Apr 16 '17 at 18:13
  • Thanks for the help with the libraries, but why would this cause the "Cannot find or load main class" error? – Trent Stevens Apr 16 '17 at 18:27

1 Answers1

0

The reason is given in the exception stack trace:

Caused by: java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path

The JVM didn't find the lwjgl native library.

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
  • I added lwjgl.jar and the natives with jarsplice, then got that other "cannot find main class" error. – Trent Stevens Apr 16 '17 at 16:21
  • @TrentStevens May be this Q&A helps: [Eclipse: Packaging a JAR with natives](http://stackoverflow.com/questions/7886316/eclipse-packaging-a-jar-with-natives?rq=1). It is about LWJGL too. – Thomas Fritsch Apr 16 '17 at 16:25