Exception in class - java

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.

Related

How to find out what java compiler was used to compile a random jar

I made my own java library which uses some external libearies such as HttpClient from Apache.
When I compile it and try to use it, I am getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpEntity
at main.Main.main(Main.java:14)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpEntity
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
Even though all dependent libraries are included in my jar.
I did some research and it looks like it is an issue with a compiler version. My lib is compiled with Java 8 while Apache libs are compiled with an older version.
My question is, why there isn't any warning about possible issues with such library upon compilation?
And how could I find out with what version of Java was used to compile these libraries?

Apache OFBiz startup exception

I am trying to setup OFBiz in my computer. So far, I have followed the step by step procedure on installing the software. The problem is when I try to run the server by executing the command java -jar ofbiz.jar I always encounter a startup exception. Even if I execute the startofbiz.bat it will display the same error:
org.ofbiz.base.start.StartupException: Cannot locate container class (org.ofbiz.service.rmi.RmiServiceContainer)
at org.ofbiz.base.container.ContainerLoader.loadContainer(ContainerLoader.java:164)
at org.ofbiz.base.container.ContainerLoader.load(ContainerLoader.java:65)
at org.ofbiz.base.start.Start.initStartLoaders(Start.java:259)
at org.ofbiz.base.start.Start.init(Start.java:96)
at org.ofbiz.base.start.Start.main(Start.java:410)
java.lang.ClassNotFoundException: org.ofbiz.service.rmi.RmiServiceContainer
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 org.ofbiz.base.util.CachedClassLoader.loadClass(CachedClassLoader.java:196)
at org.ofbiz.base.util.CachedClassLoader.loadClass(CachedClassLoader.java:169)
at org.ofbiz.base.container.ContainerLoader.loadContainer(ContainerLoader.java:162)
at org.ofbiz.base.container.ContainerLoader.load(ContainerLoader.java:65)
at org.ofbiz.base.start.Start.initStartLoaders(Start.java:259)
at org.ofbiz.base.start.Start.init(Start.java:96)
at org.ofbiz.base.start.Start.main(Start.java:410)
java.lang.ClassNotFoundException: org.ofbiz.service.rmi.RmiServiceContainer
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 org.ofbiz.base.util.CachedClassLoader.loadClass(CachedClassLoader.java:196)
at org.ofbiz.base.util.CachedClassLoader.loadClass(CachedClassLoader.java:169)
at org.ofbiz.base.container.ContainerLoader.loadContainer(ContainerLoader.java:162)
at org.ofbiz.base.container.ContainerLoader.load(ContainerLoader.java:65)
at org.ofbiz.base.start.Start.initStartLoaders(Start.java:259)
at org.ofbiz.base.start.Start.init(Start.java:96)
at org.ofbiz.base.start.Start.main(Start.java:410)
Please help!
Assuming you've run the ant run-install step as you have been following step by step instructions you should debug the exception like you would any other java exception.
Firstly in your stack trace the key lines to look at are:
{org.ofbiz.base.start.StartupException: Cannot locate container class
(org.ofbiz.service.rmi.RmiServiceContainer)}
{java.lang.ClassNotFoundException:
org.ofbiz.service.rmi.RmiServiceContainer}
These are telling you that the class, org.ofbiz.service.rmi.RmiServiceContainer, was attempted to be loaded and was not found.
You should check to see whether you have the class file RmiServiceContainer.class. In my installation of OFBiz this class is located under:
/ofbiz/framework/service/build/classes/org/ofbiz/service/rmi/RmiServiceContainer.class
If you find the class file then try rebuilding OFBiz using ant refresh.
If you could not find the class file then search for the java file that is used to create this class RmiServiceContainer.java. The java code that is compiled to created this class is located under:
/ofbiz/framework/service/src/org/ofbiz/service/rmi/RmiServiceContainer.java
If you find the Java file, again, try and rebuild OFBiz using ant refresh and confirm the class file was created. If you cannot find the java file then you should download OFBiz again.
If running ant refresh fails to fix the issue then it's likely something isn't configured correctly in your classpath.

java mail msgsend error

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.

Java classnotfound error

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.

WSDL2Java Throws Could not find main class: org.apache.axis.wsdl.WSDL2Java

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

Categories

Resources