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.
Related
I'm attempting to run a jar file on a windows VM. When testing it using the CMD prompt, I get this error -
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: java.lang.NoClassDefFoundError: java/net/http/HttpClient
at jarName.Main.removeExtinct(Main.java:250)
at jarName.Main.main(Main.java:93)
... 5 more
Caused by: java.lang.ClassNotFoundException: java.net.http.HttpClient
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
This is my MANIFEST.MF:
Manifest-Version: 1.0
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Rsrc-Class-Path: ./ selenium-server-standalone-3.7.1.jar aws-java-sdk-s3
-1.11.529.jar aws-java-sdk-kms-1.11.529.jar aws-java-sdk-core-1.11.529.
jar ion-java-1.0.2.jar jackson-dataformat-cbor-2.6.7.jar jmespath-java-
1.11.529.jar aws-java-sdk-dynamodb-1.11.529.jar httpclient-4.0.1.jar co
mmons-logging-1.1.1.jar commons-codec-1.3.jar httpcore-4.0.1.jar jackso
n-core-2.9.3.jar jackson-databind-2.9.3.jar jackson-annotations-2.9.0.j
ar postgresql-42.2.8.jar json-20190722.jar commons-net-3.6.jar jasypt-1
.9.0.jar ebay-oauth-java-client-1.1.0.jar okhttp-3.10.0.jar okio-1.14.0
.jar snakeyaml-1.20.jar joda-time-2.9.9.jar slf4j-api-1.7.25.jar seleni
um-java-3.11.0.jar selenium-api-3.11.0.jar selenium-chrome-driver-3.11.
0.jar selenium-edge-driver-3.11.0.jar selenium-firefox-driver-3.11.0.ja
r selenium-ie-driver-3.11.0.jar selenium-opera-driver-3.11.0.jar seleni
um-remote-driver-3.11.0.jar selenium-safari-driver-3.11.0.jar selenium-
support-3.11.0.jar byte-buddy-1.7.9.jar commons-exec-1.3.jar guava-23.6
-jre.jar jsr305-1.3.9.jar checker-compat-qual-2.0.0.jar error_prone_ann
otations-2.1.3.jar j2objc-annotations-1.1.jar animal-sniffer-annotation
s-1.14.jar jjwt-0.9.0.jar commons-lang3-3.7.jar gson-2.8.6.jar
Rsrc-Main-Class: jarName.Main
Class-Path: .
I think the class it's saying it can't find is httpclient-4.0.1.jar which is on the 6th line if the MANIFEST file. The only issue I can think of is the Class-Path at the end of the MANIFEST being just .
I also unzipped the .jar file, to make sure the relevant .jar files are actually present, which it is (assuming httpclient-4.0.1.jar is the correct file).
I can run other .jar files on this VM, though none with this class in it. I've updated Java as well, just in case, which didn't help.
httpclient-4.0.1.jar most probably means version v4.0.1 of org.apache.httpcomponents:httpclient.
And java.net.http.HttpClient was intriduced since 11 version of JDK.
Didn't you forget to use correct version of jre/jvm?
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.
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.
I run the following command:
C:\Projects\java -cp ./dependency.jar -jar ./dist/main.jar
Exception in thread "main" java.lang.NoClassDefFoundError: MyException
Caused by: java.lang.ClassNotFoundException: MyException
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)
Could not find the main class: Main. Program will exit.
MyException is inside dependency.jar. I also tried to replace -cp with -classpath. What do I do wrong?
The -cp options is ignored if you use -jar. If you need extra jar-files on the class-path, you should specify this in the Manifest of main.jar like this:
Class-Path: dependency.jar
(Then you can run your program using java -jar main.jar.)
Related questions:
When creating a jar file how do I retain the existing classpaths to other jar files?
Cannot find class even when jar file is in working directory
Jetty Classpath issues
problem related to MANIFEST.MF in jar
Have you tried specifying the class path in the windows environment variable CLASSPATH ?
specify your environment variable CLASSPATH and put the value of your JAVA_HOME\lib and (path to all your classes) and also include current directory by including (dot or period sign).
I have compiled a java project into a jar but I am having some issues when trying to run it
java -jar XMltoCSV.jar
Error: Could not find or load main class XMLtoCSV.class
I have created a manifest file that contains:
Main-Class: xmltocsv.XMLtoCSV
(there is a newline character in the manifest text file)
The XMLtoCSV.class does contain the main() method. I have been running this code to create the jar file:
jar cvf XMLtoCSV.jar Manifest.txt xmltocsv/*.class
And I know its working because I get:
jar cvfm XMLtoCSV.jar manifest.txt XMLtoCSV.class
added manifest
adding: XMLtoCSV.class(in = 4885) (out= 2492)(deflated 48%)
Why does it give me this error? Thanks in advance for the help
It seems I am also running into another error, what does it mean?:
Exception in thread "main" java.lang.UnsupportedClassVersionError: xmltocsv/XMLt
oCSV : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(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)
Could not find the main class: xmltocsv.XMLtoCSV. Program will exit.
Main-Class: XMLtoCSV.class
it's not right.
You have to specify something like:
Main-Class: com.mydomain.XMLtoCSV
namely the fully qualified name of the class.
See: http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
Drop the .class in your manifest.
Update:
What is the package of your main class? If your Java-File contains a statement such as
package com.google.common.base;
at the top. You need that package in your manifest. In your case that would be:
Main-Class: com.google.common.base.XMLtoCSV
If your class does not have such a package statemnent the error is something else.
(Note that com.google.common.baseis just an example of course.)
For a jar be executable, you have to be concerned with two thing on the manifest file:
1- The 'Main-Class' entry must be pointing to the class that'll be launching the application, i.e. the class where you declared the main method to start your app.
2- After all entries on the manifest file, you have to leave three lines in blank (I never found a documentation explaining why that is required but always works for me).
The simplest MANIFEST file would look like the following:
Manifest-Version: 1.0
Main-Class: com.foo.FOO
Just remember to leave three lines in blank after the last entry.
Hope I have helped.