16

I'm trying to run the sample "Hello World" from the LWJGL website

From this link: LWJGL "Getting Started"

I'm trying to do this via the command line, just so I understand the "behind the scenes" a bit better.

I've managed to compile without any errors, but when I try to run the program I'm getting this error:

C:\JavaProjects\LearningLWJGL>java -classpath .;./lib/*.jar -Djava.library.path=C:\Windows\System32 HelloWorld
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/glfw/GLFWKeyCallback
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.privateGetMethodRecursive(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.glfw.GLFWKeyCallback
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 7 more

Any ideas?

Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
yoonsi
  • 754
  • 3
  • 10
  • 23

2 Answers2

10

A CLASSPATH entry is either a directory at the head of a package hierarchy of .class files, or a .jar file. If you're expecting ./lib to include all the .jar files in that directory, it won't. You have to name them explicitly.

yoonsi
  • 754
  • 3
  • 10
  • 23
user207421
  • 305,947
  • 44
  • 307
  • 483
  • Thank you kindly. I changed the flag to "java -classpath .;./lib/jlwgl.jar" and I've got it working. I apologise but I still don't understand WHY this caused it to not work properly. Would you be so kind as to offer a little more explanation? – yoonsi Mar 08 '15 at 02:58
  • 1
    If you'll notice I didn't juse use ./lib, I used ./lib/*.jar (not sure why considering I only had one jar though...) – yoonsi Mar 08 '15 at 02:59
  • 2
    The reason obviously is that the `*.jar` syntax doesn't work. I have no idea what your last comment is supposed to mean, or to what it refers, but I expect *everybody* to have manners. – user207421 Apr 02 '15 at 07:20
  • Class path entries can contain the base name wildcard character (*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. – Alex Bitek Jun 13 '15 at 23:08
  • 1
    [Expansion of wild cards is done early, before the invocation of a program's main method, rather than late, during the class-loading process. Each element of the input class path that contains a wildcard is replaced by the (possibly empty) sequence of elements generated by enumerating the JAR files in the named directory. For example, if the directory mydir contains a.jar, b.jar, and c.jar, then the class path mydir/\* is expanded into mydir/a.jar:mydir/b.jar:mydir/c.jar, and that string would be the value of the system property java.class.path.](https://goo.gl/lE3OC3) – Alex Bitek Jun 13 '15 at 23:08
  • 1
    In my case the solution was to explicitly specify in `classpath` JAR file with the class I want to be executed (`HelloWorld` in this case) rather than provide it through the `-jar` option – Ilya Serbis Jul 10 '15 at 10:42
  • @Lu55 That's the back-to-front solution. Specifying it in the Class-Path option of the Manifest is greatly to be preferred, as is the -jar option. – user207421 Oct 14 '15 at 07:53
0

I had same issue using different dependancy what helped me is to set scope to compile.

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>compile</scope>
    </dependency>
Vlado Lesko
  • 55
  • 10