NoClassDefFoundError hibernate criterion exporting jar - java

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.

Related

running the .jar file of jalview

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

Problems exporting Jar using Weka

i've got a big problem exporting my project as a jar file (inside my project i use weka). I'm using Eclipse.
I've added in Java Build Path weka.jar and i've attached to it weka-src.jar, testing my classifier under eclipse everything works, so i've decided to create a jar (because i need that another program use it).
First of all i've created the manifest file:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ weka.jar weka-src.jar
Class-Path: .
Rsrc-Main-Class: start.Home
Main-Class: start.Home
The main class of the program is Home (inside the package start), while weka.jar and weka-src.jar are inside the /src/ directory of the eclipse program.
When i try to execute the jar created i receive this output:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: weka/classifiers/Classifier
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: weka.classifiers.Classifier
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
I think that the problem is the CLASSPATH so i've tried to solve it in this way:
I've created the Environment Variable CLASSPATH with this values:
C:\Users\tomma\Desktop\workspace Eclipse\AndroidPermissionsClassifier\src\weka.jar
C:\Users\tomma\Desktop\workspace Eclipse\AndroidPermissionsClassifier\src\weka-src.jar
but nothing changed, can someone help me please?
You are right: the classpath is the problem. Did you remove the items from the manifest classpath when you added them to the environment CLASSPATH? (Side note: place the source jar in the -sourcepath, not the classpath.)

NoClassDefFoundError executing jar using jaxrpc

I have developed a Webservice client application using jaxrpc. Within eclipse the application runs fine, however after I have exported the jar file, I get the following runtime error
D:\>java -jar Myclient2.jar
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/rpc/Service
Exception
at Mynet.MyScheduler.<init>(MyScheduler.java:47)
at Mynet.MyScheduler.<init>(MyScheduler.java:36)
at Mynet.MyNetMain.main(MyNetMain.java:11)
Caused by: java.lang.ClassNotFoundException: javax.xml.rpc.ServiceException
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
I have tried to set the CLASSPATH variable but no changes.
set CLASSPATH=%CLASSPATH%;D:\eclipse\plugins\javax.xml.rpc_1.1.0.v201209140446\lib\jaxrpc.jar
set CLASSPATH=%CLASSPATH%;D:\eclipse\plugins\org.apache.axis_1.4.0.v201005080400\lib\axis.jar
echo %CLASSPATH%
java -jar Myclient2.jar
I am rather new to java so definitely a newbie question
KR
You should consider migrating your web service to JAX-WS. JAX-RPC is an older java web service technology that is unlikely to be maintained much moving forward.
But the single biggest benefit you will experience is that all of the JAX-WS runtime and tooling has been part of the Java JDK since Java 6. This means that you can build web services with no runtime library dependencies.
Anytime that you get "java.lang.NoClassDefFoundError"; it is very probable that you are missing a jar file.
you should search for the jar file containing "javax/xml/rpc" and then add it to your classpath or as a dependency to your maven project.
Here you should find them:
http://search.maven.org/
http://mvnrepository.com/

java.lang.NoClassDefFoundError with LWJGL

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.

Problem loading files from jar (classpath problem)

When I try to execute this code:
package uk.org.infectogenomics.agent;
import uk.org.infectogenomics.Agent.qa.Quasr;
public static void main(String[] args) {
//ommited some code
Runnable step = new Quasr(wf.getStepByPos(1));
}
I get:
Exception in thread "main" java.lang.NoClassDefFoundError: uk/org/infectogenomic
s/Agent/qa/Quasr
at uk.org.infectogenomics.agent.Agent.main(Agent.java:55)
Caused by: java.lang.ClassNotFoundException: uk.org.infectogenomics.Agent.qa.Quasr
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
Here is my manifest file:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.6.0_25-b06 (Sun Microsystems Inc.)
Class-Path: lib/mysql-connector-java-5.1.17-bin.jar lib/aws-java-sdk-1.2.6.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: uk.org.infectogenomics.agent.Agent
And here is the listing of the jar file itself:
META-INF/
META-INF/MANIFEST.MF
uk/
uk/org/
uk/org/infectogenomics/
uk/org/infectogenomics/agent/
uk/org/infectogenomics/agent/Assembly/
uk/org/infectogenomics/agent/hostEl/
uk/org/infectogenomics/agent/qa/
uk/org/infectogenomics/agent/taxonomy/
uk/org/infectogenomics/agent/Agent.class
uk/org/infectogenomics/agent/Assembly/Newbler.class
uk/org/infectogenomics/agent/Assembly/Velvet.class
uk/org/infectogenomics/agent/DBAccessor.class
uk/org/infectogenomics/agent/DateUtils.class
uk/org/infectogenomics/agent/Status$1.class
uk/org/infectogenomics/agent/Status$2.class
uk/org/infectogenomics/agent/Status$3.class
uk/org/infectogenomics/agent/Status$4.class
uk/org/infectogenomics/agent/Status.class
uk/org/infectogenomics/agent/Workflow.class
uk/org/infectogenomics/agent/WorkflowStep.class
uk/org/infectogenomics/agent/agent.properties
uk/org/infectogenomics/agent/hostEl/Fastq2FQone.class
uk/org/infectogenomics/agent/hostEl/RepeatMasker.class
uk/org/infectogenomics/agent/hostEl/SplitFiles.class
uk/org/infectogenomics/agent/qa/Quasr.class
uk/org/infectogenomics/agent/taxonomy/Phymbl.class
So what should the classpath be and since I'm using Netbeans I would assume this is the job of the IDE to actually take care of this. This happens only when I package everything inside a jar, when I run the code from the IDE everything works as expected.
Look at the class name it can't find:
uk/org/infectogenomics/Agent/qa/Quasr
Now look at your jar file contents:
uk/org/infectogenomics/agent/qa/Quasr.class
There's a casing difference. My guess is that at some point you've switched over the package name from lowercase (which it should be, IMO) but that you're on Windows (with case-insensitive file system), so the existing "agent" directory was preserved rather than it being wiped and replaced with "Agent".
If you rebuild from scratch, it may well sort everything out. On the other hand, I'd suggest changing the package name to follow the normal Java naming conventions.

Categories