1

I am relatively new to Java, and I have made a script which uses the LWJGL 3. The program runs perfectly fine within the Eclipse IDE but when I attempt to export it as a runnable Jar file (I checked package required libraries field) and then attempt to run it through windows command line I get the error message as follows:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: java.lang.NoClassDefFoundError: org/lwjgl/glfw/GLFW
    at renderEngine.TestEngine.main(TestEngine.java:18)
    ... 5 more
Caused by: java.lang.ClassNotFoundException: org.lwjgl.glfw.GLFW
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 6 more

I am assuming this is an issue caused by a lack of access to the libraries I imported, but after searching the web for a while I could not find a single proper guided answer to solving the question. Most of the time it was someone asking the question and then just stating they solved it themselves or someone else explaining the issue but not actually assisting with it. I am hoping someone can assist me with a guided explanation of how to fix this issue, and also if it could be explained as to avoid future issues.

If any more information is needed to assist with the issue I will be happy to provide it.

UPDATE: It seems that the issue is with GLFW and not the library as a whole. As re-reading the error, the only thing that cannot be found or loaded is GLFW when I am also using other imports from the same library such as OpenGL. Also, the line it specifies is the line in which I call a function from GLFW and not when I import the package, don't know if that is because errors don't get called when imports are unsuccessful or if there is another issue possibly within the package itself. I don't know if I am correct just trying to help by providing more information.

Thanks, Oliver :)

2
  • Do you have any problem while exporting the program into runnable jar files?
    – sharky
    Jan 2, 2019 at 6:24
  • No, I have encountered no issues during the export. The issue arose when attempting to run the file through the windows command line using the command: java -jar FileName.jar. The error as shown above in the original post is what I received after typing the command.
    – Oliver
    Jan 3, 2019 at 0:05

1 Answer 1

1

You can export your project as a 'Runnable jar' (Right mouse on project -> Export -> Runnable jar) you have the option to package all dependencies into the generated jar.

Use highlighted library handling option.

enter image description here

2
  • OP has already mentioned that he has created the jar this way.
    – Rahul
    Jan 2, 2019 at 5:08
  • As Rahul has already mentioned, I created the jar through the way you recommended and have encountered no issues during the exportation.
    – Oliver
    Jan 3, 2019 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.