I follow this starter tutorial.
I can not run the code with this command :
$ java -cp gs-gradle-0.1.0.jar hello.HelloWorld
I have this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/joda/time/LocalTime
at hello.HelloWorld.main(HelloWorld.java:11)
Caused by: java.lang.ClassNotFoundException: org.joda.time.LocalTime
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
All import classes are not found. But with gradle command it works :
$ ./gradlew run
Why with java command, it doesn't work ?
Thanks
Of course it does not work, the Tutorial also told you so.
The application plugin adds the run task (and other tasks) that put your dependency on the classpath.
If you use the distZip or distTar task you get an archive with all your dependencies and with start scripts that set the correct classpath that you can use to run your application.
Read more about the application plugin at https://docs.gradle.org/current/userguide/application_plugin.html.
Related
I write a Java program that read text from excel.So I import some jar like this: poi-3.10-beta2-20130904.jar, poi-ooxml-3.10-beta2-20130904.jar, etc., I can run the program correctly in eclipse.But when I package this program with maven to the directory(C:\workspace2\change\bin),
Then I run this program in command like this :
C:\workspace2\change\bin>java GenerateVar
it occurs this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Cell
at GenerateVar.execute(GenerateVar.java:59)
at GenerateVar.main(GenerateVar.java:25)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Cell
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)
... 2 more
You need to specify classpath with all other jars/classes you use in your program.
E.g. Setting multiple jars in java classpath
When you run it from eclipse in the console there's a command that could be used to run the project, you could copy/paste it from the console to your command line.
In the command java GenerateVar you didn't set -cp option. With this option the command line will look like
java -cp poi-3.10-beta2-20130904.jar poi-ooxml-3.10-beta2-20130904.jar ... GenerateVar
Assumed the libraries are in the current dir.
How to use maven plugins to add dependency to your project and build jar you can find here.
See also this answer if you want to modify manifest.mf manually.
over, I change the way do what I want to do. I use the fat jar which is the eclipse plugin to package the program
i'm trying to run testng tests using command line like this :
C:\Documents and Settings\Administrateur\Bureau\automatic tests testNG>java -cp
C:\Documents and Settings\Administrateur\.m2\repository\org\testng\testng\6.3.1\
testng-6.3.1.jar org.testng.TestNG testng.xml
but i'm getting this error :
Exception in thread "main" java.lang.NoClassDefFoundError: and
Caused by: java.lang.ClassNotFoundException: and
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: and. Program will exit.
So How to add testNG to the classpath.
Thanks
The spaces in the filename are confusing things - Java thinks that only the c:\Documents part is in the classpath argument. Try this:
java -cp
"C:\Documents and Settings"\Administrateur\.m2\repository\org\
testng\testng\6.3.1\testng-6.3.1.jar org.testng.TestNG testng.xml
(where the whole thing is on one line and there's no break after "org" of course)
If you want to run via java on command line, you'll need to either enquote your path ("C:\Documents and Settings\Administrateur\.m2\repository\org\testng\testng\6.3.1\") or alter slightly as follows: C:\Documents%20and%20Settings\Administrateur\.m2\repository\org\testng\testng\6.3.1\. You may also want to run via maven to avoid having to specify this classpath info.
I m trying to compile an open source software . The build works fine and results into a jar file "five-server.jar". When I try to run this file from cmd , I get these errors.
C:\Users\vickey\code\five-server\dist\main>java -jar five-server.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/SWTError
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.SWTError
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: org.devtcg.five.Main. Program will exit.
any suggestion what is wrong?
The SWT Jar files are platform dependent.
See http://www.jarfinder.com/index.php/java/info/org.eclipse.swt.SWTError
e.g. on Windows a suitable jar would be:
org.eclipse.swt.win32.win32.x86_3.1.0.jar
or on Mac OS X:
swt-macosx-3.0m7.jar
and so on.
You might run into call kinds of followup problems if you add this dependency e.g. whether you are
using 32bit or 64bit libraries.
It is too bad that these kind of dependency problems show up more often than not these days :-(
You have to set the classpath so that it includes at least the class org.eclipse.swt.SWTError
or the jar containing it:
java -classpath path/to/jar/containing/org.eclipse.swt.SWTError -jar five-server.jar
You should also set the Main-class attribute in the manifest file in the five-server.jar
Following the #Wolfgang Fahl answer, you might download the references here:
Standard Widget Toolkit » 4.3 x86
Maven reference:
https://mvnrepository.com/artifact/org.eclipse.swt.org.eclipse.swt.win32.win32.x86.4.3.swt/org.eclipse.swt.win32.win32.x86/4.3
Jar file:
http://central.maven.org/maven2/org/eclipse/swt/org/eclipse/swt/win32/win32/x86_64/4/3/swt/org.eclipse.swt.win32.win32.x86_64/4.3/org.eclipse.swt.win32.win32.x86_64-4.3.jar
Standard Widget Toolkit » 4.3 x64
Maven reference: https://mvnrepository.com/artifact/org.eclipse.swt.org.eclipse.swt.win32.win32.x86_64.4.3.swt/org.eclipse.swt.win32.win32.x86_64/4.3
Jar file:
http://central.maven.org/maven2/org/eclipse/swt/org/eclipse/swt/win32/win32/x86_64/4/3/swt/org.eclipse.swt.win32.win32.x86_64/4.3/org.eclipse.swt.win32.win32.x86_64-4.3.jar
I have a webservice client created using cxf. When I run from eclipse I dont get any errors. But when I create a jar out of the files and run it from cmd prompt , I get NoclassDef exception or ClassNot found exception. I have set the classpath, java home correct.
1. Exception
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
2. Exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/cxf/databinding/DataBinding
Caused by: java.lang.ClassNotFoundException: org.apache.cxf.databinding.DataBinding
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)
The web service is in C# wcf and the client was created without JAXBinding element.
Anyhelp will be appreciated.
Thanks,
Priya.R
This is a typically and easiy-to-solve classpath problem: The cxf library (-ies) is/are missing on the classpath. Start the application like this:
java -cp <youJar.jar>;<cxf.jar>[;<another-cxf.jar>;...] my.pkg.Application
You'll have to replace the name of the main class and the values of the -cp parameter with the paths and names of your jar and all other libraries that are required to run the application.
Why does it work from eclipse: In eclipse, you've set the build path correctly, but this builds path is not exported or added to the jar.
I am trying to create the java files from a remote webservice. I downloaded axis 1.4, copied the lib folder to c:\data\axis\lib which contains of these files:
axis.jar
axis-ant.jar
commons-discovery-0.2.jar
commons-logging-1.0.4.jar
jaxrpc.jar
log4j.properties
log4j-1.2.8.jar
saaj.jar
wsdl4j-1.5.1.jar
I added the c:\data\axis\lib folder to the %AXISCLASSPATH%. Now I am trying to create the java classes using this cmd:
java -cp %AXISCLASSPATH% org.apache.wsdl.WSDL2JAVA http://myurl.com?wsdl
However I keep getting the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/wsdl/
WSDL2Java
Caused by: java.lang.ClassNotFoundException: org.apache.axis.wsdl.WSDL2Java
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: org.apache.axis.wsdl.WSDL2Java. Program will exit.
Can someone help me to get this working?
Add the jars to the classpath individually if you're using a Java version before 6. If you're using Java 6, see here if you want to use wildcards.
try
java -cp %AXISCLASSPATH% org.apache.wsdl.WSDL2Java http://myurl.com?wsdl
Class names are case sensitive
Login as eucalyptis and compile and it will find all of the jars - this took me forever to figure out!
package structure is wrong. Please use org.apache.axis.wsdl.WSDL2Java