2

I've read around a lot but haven't been able to find a solution yet.

I'm using lwjgl, it needs 2 jars and a native library to run: lwjgl.jar, lwjgl_util.jar and the natives library. I've tried this in every way i could think of, anyway, I'm trying with a command like this at the moment:

java - Djava.library.path="libs/natives/" -cp libs/jars/lwjgl.jar:libs/jars/lwjgl_util.jar DisplayTest.class 

but in every way i try, i get:

Exception in thread "main" java.lang.NoClassDefFoundError: DisplayTest/class Caused by: java.lang.ClassNotFoundException: DisplayTest.class at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) Could not find the main class: DisplayTest.class. Program will exit 

Oh and it might be worth to mention that I'm working on a linux terminal. Also, i get this to run perfectly fine in eclipse so I can't really understand whats up here.

2
  • is there a blank space right before the Djava.library.path="libs/natives/"?? it should be -Djava.library.path="libs/natives/", the construct -D is used to define systems properties Commented Sep 4, 2012 at 16:54
  • yeah, sorry, it was supposed to be -D, i had some issues when writing the thread :) Commented Sep 4, 2012 at 17:13

4 Answers 4

4

First off, you just need to pass the class name to java:

java -Djava.library.path="libs/natives/" -cp libs/jars/lwjgl.jar:libs/jars/lwjgl_util.jar DisplayTest 

(linebreaks for readability)

I would try the following:

1) Use the CLASSPATH enviroment variable, as in:

 CLASSPATH=.:/path/to/lwjgl/lwjgl.jar:/path/to/lwjgl/lwjgl_util.jar export CLASSPATH 

Notice the dot (.) at the very beginning of the classpath;

2) Run your java application:

 java -Djava.library.path="libs/natives" DisplayTest 

If this works, add the commands above to a shell script. Good luck!

Sign up to request clarification or add additional context in comments.

3 Comments

I'd like to add that the '/' in "DisplayTest/class" is the clue here. Class names can't have a '/' in them!
First of all, thanks alot for the reply, however it did work for me. I Still get Could not find the main class: DisplayTest stuff. Even tried to copy your code right off, still didnt work :(
Sorry, obviously this fixed the error i provided, however the one that appeared after the .class stuff was fixed was so much like it i didnt notice any change for a while.
1

Try taking off the ".class" e.g.

java -Djava.library.path="libs/natives/" -cp libs/jars/lwjgl.jar:libs/jars/lwjgl_util.jar DisplayTest.class

Would become:

java -Djava.library.path="libs/natives/" -cp libs/jars/lwjgl.jar:libs/jars/lwjgl_util.jar DisplayTest

By adding the ".class", you're telling the command that you have a Class called "class" in a directory called "DisplayTest", which is not what you're trying to achieve. This is shown in this line:

Exception in thread "main" java.lang.NoClassDefFoundError: DisplayTest/class 

4 Comments

Thanks alot for the reply! However also, this did not work for me, still get the class not found stuff :(
@user1295313 That's okay :) What does the output say now?
@user1295313 Think I may have solved the problem. Try putting ".;" at the start of your classpath e.g. java -Djava.library.path="libs/natives/" -cp .;libs/jars/lwjgl.jar:libs/jars/lwjgl_util.jar DisplayTest
@user1295313 Also, you have used ":" instead of ";" between your jar files, only just noticed.
0

when triggering java command use -cp or -classpath. Enter just java command to see the usage

Comments

0

I also got a similar error.

Just include your working directory , (where you have your own class), along with the libraries that you need in your classpath at runtime.

NoCLassDefFoundError occurs when the machine is unable to find your .class files during runtime (even though they have been compiled ,i.e it won't give an error while compiling but only during runtime)

STEP 1: to compile javac -classpath "path/to/lib1:path/to/lib2" yourfile.java STEP 2: to run java - classpath "path/to/lib1:path/to/lib2:path/to/your/currentdirectory/wherethedotclass/filearecreated/" yourfile

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.