So, I am afraid that I have to join the crowds flocking here and asking: "What's wrong with my code?"
I've recently started coding in Java and I've had none of this error until I tried using lwjgl in a project. So, the question is: What is wrong with my JAR when I get the following:
java -cp \lib\win32\lwjgl.jar -jar Valor.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/opengl/Display
at bin.Disp.createWindow(Disp.java:18)
at bin.Thread.gameLoop(Thread.java:13)
at Main.main(Main.java:4)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.opengl.Display
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
... 3 more
As is, I am extremely confused about this. I've gone through seven or eight posts here about this very problem, and another five or six on other web sites, yet none of the methods those people used seem to work for me.
Currently, my file structure is:
Valor
-Valor.jar
lib
win32
-lwjgl.jar
-lwjgl.dll
Manifest:
Manifest-Version: 1.0
Main-Class: Main
I did try defining a classpath here... Didn't work. So, I'm pretty much as confused as I can possibly get. Thank you for your help.
Edit: This error doesn't occur while running in Eclipse, only when I export and try to run it myself.
Try to run it like this:
java -cp lib\win32\lwjgl.jar;Valor.jar Main
The problem is that the -cp option is ignored when -jar is used.
Alternativelly you could extend the class path by adding a Class-Path: entry in your manifest and puting lib\win32\lwjgl.jar in it.
Class-Path: lib\win32\lwjgl.jar
use this link to install ljgl and define your classPath : http://www.lwjgl.org/wiki/index.php?title=Setting_Up_LWJGL_with_Eclipse
By running java -cp \lib\win32\lwjgl.jar -jar Valor.jar you're telling Java to look for LWJGL classpath near the root of your filesystem. Seeing your directory structure, use:
java -cp .\lib\win32\lwjgl.jar -jar Valor.jar
Notice the . at the beginning.
Related
First time trying to run some Java code under Windows here, and I got:
D:\Tmp>java JDBC_SQLServer
Picked up _JAVA_OPTIONS: -Xmx512M
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at JDBC_SQLServer.main(JDBC_SQLServer.java:19)
I.e., java finds main but didn't find the lib. Now, --
D:\Tmp>java -classpath "C:\Program Files\Java\jdk1.8.0_162\lib" JDBC_SQLServer
Picked up _JAVA_OPTIONS: -Xmx512M
Error: Could not find or load main class JDBC_SQLServer
I.e., java finds the sqlserver.jdbc.SQLServerDriver lib but can't find main now.
The JDBC_SQLServer is just a hack from
https://learn.microsoft.com/en-us/sql/connect/jdbc/connection-url-sample
How to solve it? Thx.
The classpath needs to contain the current directory (in order to find your class and its main-method and the jar-file (not only a directory with jars in it), so a call could look like this:
D:\Tmp>java -cp "C:/mssql/lib/sqljdbc41.jar;." JDBC_SQLServer
You don't need to use backslashes for the paths and because backslashes are often parsed specially by the shell you use, I personally try to avoid them as much as possible.
I am trying to get Jalview [1] running on my windows 7 system. The standard installation works without error but when starting (the .exe file) it I get "Windows error 2 occured while loading the Java VM". As this error is quite general I tried then
C:\Program Files (x86)\Jalview>java -jar jalview.jar
which leads to:
Java version: 1.8.0_121
x86 Windows 7 6.1
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Layo
ut
at jalview.bin.Jalview.doMain(Jalview.java:210)
at jalview.bin.Jalview.main(Jalview.java:180)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Layout
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)
... 2 more
any ideas what is going wrong?
Thx
Morpheus
[1] http://www.jalview.org/Download
This error "java.lang.NoClassDefFoundError" occurs when there is a class missing in your respective packages.
I suggest please check if the class "Layout" is present at path : org/apache/log4j
If not then its correct that you have some missing files/libraries of log4j in the classpath.
Please vote and mark the solution if useful.
Thanks!
First check that in C:\Program Files (x86)\Jalview\lib the library min-jabaws-client-*.jar exists.
To run it from command line
cd C:\Program Files (x86)\Jalview
java -cp jalview.jar;lib/* jalview.bin.Jalview
I've written a program to read in data from a text file and do some simple calculations, then print out those calculations. That part works great.
Afterward, I added in some code to do a t-test, using the TTest class (org.apache.commons.math3.stat.inference.TTest). So, I downloaded commons-math3-3.6.jar from the Apache Commons download page and put the JAR file in the same folder as the rest of my Java code for this program.
I use the following command in Windows to compile, which works fine:
javac -cp ./commons-math3-3.6.jar ./FootballTeam.java ./Main.java
But I can't figure out how to correctly run the program. I've tried this:
java Main
which executes everything up to the t-test perfectly, and then gives the expected error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/stat/inference/TTest
at Main.main(Main.java:32)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.stat.inference.TTest
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)
... 1 more
I've also tried this:
java -cp commons-math3-3.6.jar Main
which gives me this:
Error: Could not find or load main class Main
I cannot for the life of me figure out how to properly set the classpath here. Can someone provide me some assistance? Thank you!
The Main class cannot be found because the current directory (.) is not on your classpath.
To add it, on Windows:
java -cp ".;commons-math3-3.6.jar" Main
On *n?x:
java -cp ".:commons-math3-3.6.jar" Main
I'm trying to export a java stand-alone class that uses hibernate. It's a really simple read/insert procedure. I'm stuck with this error
C:\Users\Admin\Desktop>java -jar ImportDatiMeteo2.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/criteri
on/Criterion
at openplan.openergy.standalone.ImportDati.main(ImportDati.java:24)
Caused by: java.lang.ClassNotFoundException: org.hibernate.criterion.Criterion
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
... 1 more
I was thinking it could be a manifest file problem so i checked. It seem ok to me.
Manifest-Version: 1.0
Class-Path: lib/antlr-2.7.6rc1.jar lib/asm-attrs.jar lib/asm.jar
lib/c3p0-0.8.5.2.jar lib/cglib-2.1.3.jar lib/cleanimports.jar
lib/commons-collections-2.1.1.jar lib/commons-logging-1.0.4.jar lib/concurrent-1.3.2.jar
lib/connector.jar lib/dom4j-1.6.1.jar lib/ehcache-1.1.jar lib/hibernate3.jar
lib/jaas.jar lib/jacc-1_0-fr.jar lib/jaxen-1.1-beta-7.jar
lib/jdbc2_0-stdext.jar lib/jgroups-2.2.7.jar lib/jta.jar lib/log4j-1.2.11.jar
lib/log4j-1.2.9.jar lib/oscache-2.1.jar lib/proxool-0.8.3.jar
lib/swarmcache-1.0rc2.jar lib/xerces-2.6.2.jar lib/xml-apis.jar
Created-By: 1.6.0_21 (Sun Microsystems Inc.)
Main-Class: openplan.openergy.standalone.ImportDati
In my Eclipse all the project work properly, does anyone know where the problem is?
You need to add those libraries in classpath as you are running it from command line :
C:\> java -classpath <referenced-jars> -jar ImportDatiMeteo2.jar
in myEclipse all the project work properly, does anyone know where the problem is ?
--> Because Eclipse will take care of your classpath and adding libraries in your classpath.
Please check Library handling option in your Eclipse export dialog. On my side it works fine with hibernate with Extract required libraries into generated JAR selected.
So i need to write a program that accesses and modifies an SQLite DB for a school program and am looking at the basics firstly. Now, I am looking at this to get me started: link text. The problem is that when i compile Test.java (The example code on the website) and then run the command:
java -cp .:sqlitejdbc-v056.jar Test
like it tells me to, i get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: Test
Caused by: java.lang.ClassNotFoundException: Test
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Test. Program will exit.
Test.java, Test.class and sqlitejdbc-v056.jar are all in the same folder so they should find each other. Does anybody have an idea about what i am doing wrong?
According to the java.lang.NoClassDefFoundError: Test, the Test class cannot be found in the CLASSPATH. But you wrote that Test.class is available in the current directory so I'm gonna guess something. Actually, I think that you are not using the right CLASSPATH separator character (which is platform dependent) and thus not building correctly the CLASSPATH. On Windows, you should use ; instead of :. If this happens to be the case, you should try this:
java -cp .;sqlitejdbc-v056.jar Test
If you are on a unix-like platform, forget this answer, the problem is elsewhere.
As the exception message is saying, the problem is that it cannot find the class Test. So the problem is not finding SQLite, but finding your Test class.
Just a guess, but I am wondering if there is an issue with how you compiled. In the Test.java, does the class belong to a package? If so, you need to compile it using the -d flag so that it gets put in the appropriate sub-directory.