Showing posts with label NoClassDefFoundError. Show all posts
Showing posts with label NoClassDefFoundError. Show all posts

Monday, January 27, 2014

Eclipse : Caused by: java.lang.ClassNotFoundException / Exception in thread "main"

java.lang.NoClassDefFoundError: com/javaxp/test
Caused by: java.lang.ClassNotFoundException: com.javaxp.Test
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Exception in thread "main" 


There could be a couple of reasons for the above error

1. .class files not created properly

Try
Project -> Clean -> Clean all projects / Clean project selected below -> OK

2. JVM is not able to pick the classpath

Try
right click on the project -> Properties -> Java Compiler -> unclick the first box saying 'Enable project specific settings' -> Apply -> OK

3. A missing JAR file in the classpath

Try
right click on the project -> Properties -> Java Build Path -> Libraries -> (Remove unwanted missing jar files if any) -> OK

Hope this helps in most of the cases.

Thursday, October 18, 2012

Java : Read / Write Excel file (.xls or .xlsx) using Apache POI


We will see how we can read or write excel file (.xls or .xlsx) using Apache POI. To know more about Apache POI, click here.

You can download latest version of JAR files from http://poi.apache.org/download.html.

In our case we are using Apache POI 3.8. To run below example you will need to download poi-bin-3.8-20120326.zip file from http://poi.apache.org/download.html. You will get below JAR files, add those in your claspath.

  • dom4j-1.6.1.jar
  • xmlbeans-2.3.0.jar
  • poi-3.8-20120326.jar
  • poi-ooxml-3.8-20120326.jar
  • poi-ooxml-schemas-3.8-20120326.jar

Please see the self explanatory Java code.

Tuesday, May 1, 2012

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
        at org.springframework.context.support.AbstractApplicationContext.(AbstractApplicationContext.java:145)
        at org.springframework.context.support.AbstractRefreshableApplicationContext.(AbstractRefreshableApplicationContext.java:84)
        at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.(AbstractRefreshableConfigApplicationContext.java:59)
        at org.springframework.context.support.AbstractXmlApplicationContext.(AbstractXmlApplicationContext.java:58)
        at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:136)
        at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
        at TestHelloSpring.main(TestHelloSpring.java:7)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
        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)
        ... 7 more

If you get above error, probably your application is not able to find commons-logging.jar in classpath.

Download the latest version of JAR file from below URL and add it to classpath of your applications classpath

http://commons.apache.org/logging/download_logging.cgi

To know more about Apache Commons Logging, click here

Wednesday, April 4, 2012

java.lang.NoClassDefFoundError: org/glassfish/ha/store/api/BackingStoreException


If you get below error, Please add ha-api.jar file in your classpath.

SEVERE: WSSERVLET11: failed to parse runtime descriptor: java.lang.NoClassDefFoundError: org/glassfish/ha/store/api/BackingStoreException
java.lang.NoClassDefFoundError: org/glassfish/ha/store/api/BackingStoreException
 at com.sun.xml.ws.transport.http.servlet.ServletAdapter.(ServletAdapter.java:95)
 at com.sun.xml.ws.transport.http.servlet.ServletAdapterList.createHttpAdapter(ServletAdapterList.java:77)
 at com.sun.xml.ws.transport.http.servlet.ServletAdapterList.createHttpAdapter(ServletAdapterList.java:53)
 at com.sun.xml.ws.transport.http.HttpAdapterList.createAdapter(HttpAdapterList.java:77)
 at com.sun.xml.ws.transport.http.HttpAdapterList.createAdapter(HttpAdapterList.java:71)
 at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:267)
 at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:153)
 at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:131)
 at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:152)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4681)




You may need to add ha-api.jar jar file in your lib folder of the server OR the project in which you are getting the above error.

You can download latest version of JAR file (E.g. JAXWS2.2.6-20120220.zip ) from http://jax-ws.java.net/
Extract the file in your local machine you will find this file jaxws-ri/lib/ha-api.jar. Add it to your class path and i hope you may get rid of the above error.

Thursday, November 10, 2011

Exception in thread "main" java.lang.NoClassDefFoundError

If you get below mentioned error

Exception in thread "main" java.lang.NoClassDefFoundError: /home/test (wrong name: test)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: /home/test.  Program will exit.

Possible reason could be the class you are trying to run do not contains main method. Make sure that main method is present in the Java program which you are trying to run.