I am using JavamailAPI, I downloaded and installed the javamail-1.4.4 and jaf-1.1.1.
Added the mail.jar and activation.jar to the CLASSPATH. Ii am able to compile the msgsend class, when i trying to run the msgsend class i am getting the following exception.
Exception in thread "main" java.lang.NoClassDefFoundError: msgsend/java
Caused by: java.lang.ClassNotFoundException: msgsend.java
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: msgsend.java. Program will exit.
Please any can help me in solving this issue.
Thanks in advance..
Looks like you are trying to launch your program by
java msgsend.java
but the java expects a class name, not a file name.
java msgsend
Also, class names in Java should be upper-case.
First, you will need to compile your msgsend.java using javac and then run it as follows:
java msgsend
See that I removed the .java extension as java will look for msgend.class.
Related
I recently moved a project from one machine to another but I am now given an error when attempting to run java files on the new machine. I'm trying to run a java file from part of an Android project in command prompt but I am given an error. The file compiles okay but fails to run. Here is the error I am given;
Exception in thread "main" java.lang.NoClassDefFoundError: ChatServer (
e: edu/UTEP/android/ChatServer)
at java.lang.ClassLoader.defineClass1(Native Method)
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$100(Unknown Source)
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)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Any ideas why I am receiving this error?
Your ChatServer is having a package declaration of edu.UTEP.android in the top. So either you need to remove that package declaration recompile your java file again and run it
(or)
you need to create folder structure like this
CurrentDir/edu/UTEP/android/
Keep your java file in android folder and invoke java ChatServer from CurrentDir. Any of these two will solve the issue :-)
For more info on packages, you can refer to my previous answer on a similar issue here
Make sure that the .jar that provides ChatServer is in your runtime Classpath.
This issue rise when jvm don't file class path.
check where u have placed your jar file or lib folder.
Move to that directory then run javac and then java .
Issue will be resolved.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
at org.apache.commons.httpclient.methods.ExpectContinueMethod.<init>(ExpectContinueMethod.java:93)
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.<init>(EntityEnclosingMethod.java:119)
at org.apache.commons.httpclient.methods.PostMethod.<init>(PostMethod.java:106)
at SMSServiceJava.CSoftHttpClientSMSService.sendSimpleSMS(CSoftHttpClientSMSService.java:113)
at SMSServiceJava.CSoftHttpClientSMSService.main(CSoftHttpClientSMSService.java:219)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.DecoderException
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)
... 6 more
whenever I am running the program in eclipse I am getting the above mentioned exception. whenever I already been passed the relevant package in my classpath. can anyone tell me how to resolve this?
Add the jar(Commons-codec.jar) file needed for this org.apache.commons.codec.DecoderException
Download it from here and put it in classpath
http://commons.apache.org/proper/commons-codec/download_codec.cgi
You need commons-codec.jar on your classpath.
Reference: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
Please make sure that org-apache-commons-codec.jar is present on your class-path. You can download this commons-codec jar file from apache website.
This jar file contains org/apache/commons/codec/DecoderException class, and hence add it to the classpath must resolve your problem.
NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available during compile time. For example if we have a method call from a class or accessing any static member of a Class and that class is not available during run-time then JVM will throw NoClassDefFoundError.
For more
Try to include commons-codec-XXX.jar.
I am trying to execute the performance-meters.jar according to the tutorial at
http://marklogic.github.io/performance-meters/tutorial.html
using the command
java -cp performance-meters.jar:xcc.jar com.marklogic.performance.PerformanceMeters
I am getting the following error:
D:\MBS\performance-meters-master\performance-meters-master\classes>java -cp performance-meters.jar:xcc.jar com.marklogic.performance.PerformanceMeters
Exception in thread "main" java.lang.NoClassDefFoundError: com/marklogic/performance/PerformanceMeters
Caused by: java.lang.ClassNotFoundException: com.marklogic.performance.PerformanceMeters
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: com.marklogic.performance.PerformanceMeters. Program will exit.
I have kept both the jar files in the same folder.
Links to the jar files are:
http://developer.marklogic.com/code/performance-meters
[http://developer.marklogic.com/products/xcc][3]
Any help would be appreciated.
try to use semicolon instead colon in your cp declaration.
java -cp performance-meters.jar;xcc.jar com.marklogic.performance.PerformanceMeters
You are using windows system or Unix? If windows then I think you need to use ; and not : in separating jars as follows:
java -cp performance-meters.jar ; xcc.jar com.marklogic.performance.PerformanceMeters
I am trying execute a java class which accesses a method in a jar file.My package structure is com.xmlpost.XmlPostInit.java and it resides under the directory:
D:\Workspace\Test\bin
I am using the command below. Note, cs.jar contains the class com.xmlpost.XmlPostInit
D:\Workspace\Test\bin>java -classpath D:\FatWire\JSK\7.6.0\App_Server\apache-tomcat-6.0.18\webapps\cs\WEB-INF\lib\cs.jar com.xmlpost.XmlPostInit
.. which gives me following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/xmlpost/XmlPostInit
Caused by: java.lang.ClassNotFoundException: com.xmlpost.XmlPostInit
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: com.xmlpost.XmlPostInit. Program will exit.
You have to add your bin directory to the classpath too, as the JVM needs to look inside it to find your class. As you are running inside it, you can refer localy it with ".":
D:\Workspace\Test\bin>java -classpath .;D:\FatWire\JSK\7.6.0\App_Server\apache-tomcat-6.0.18\webapps\cs\WEB-INF\lib\cs.jar com.xmlpost.XmlPostInit
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.