Solved

java.lang.NoClassDefFoundError

Posted on 2014-01-20
11
1,382 Views
Last Modified: 2014-02-06
Hi,
I have the following file :

package com.yatra.extremesearch.app;

import org.apache.log4j.Logger;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ExtremeSearchApp {
	private static final Logger logger = Logger.getLogger(ExtremeSearchApp.class);
	
	public static void main(String args[]){
		
		 try {
			 logger.info("=====Starting Extreme search======");
			 new ClassPathXmlApplicationContext("classpath*:spring/root-context.xml");
			
			} catch (Exception e) {
				logger.error(e.getMessage());
			}
		}
}

Open in new window


when i start debugger on this i get the following error :

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/support/ClassPathXmlApplicationContext
      at com.yatra.extremesearch.app.ExtremeSearchApp.main(ExtremeSearchApp.java:13)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.support.ClassPathXmlApplicationContext
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

How do i resolve it ?

Thanks
0
Comment
Question by:Rohit Bajaj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 8

Expert Comment

by:Surrano
ID: 39793671
the spelling looks ok but doublecheck.
What is your classpath? Does it include spring api? Which version?
0
 

Author Comment

by:Rohit Bajaj
ID: 39793680
Hi,
I added some jars in the classpath by selecting run configurations in eclipse.
This error went away but now i am getting the following error :

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/E:/SvnCheckOut/trunk_ExtremeSearch/libs/jars/logging/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/E:/SvnCheckOut/trunk_ExtremeSearch/ExtremeSearch/target/libs/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/beans/factory/support/ConfigurableBeanFactoryUtils
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:273)
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:87)
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:72)
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:63)
      at com.yatra.extremesearch.app.ExtremeSearchApp.main(ExtremeSearchApp.java:13)
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.support.ConfigurableBeanFactoryUtils
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
      ... 5 more
0
 
LVL 8

Accepted Solution

by:
Surrano earned 500 total points
ID: 39793701
First, the SLF4J problem seems to be due to some deployment (ant or maven build script?): the classpath contains both the input location of the libs (trunk_ExtremeSearch/libs/...) and the target of the build where these jars have been copied (trunk_ExtremeSearch/ExtremeSearch/target/libs). If there's such a deployment then the first one is needed for building only and should not be on the classpath of the configuration to run.

Second, some spring lib is still missing from classpath but at this point I think you shouldn't ad it to classpath; you should add it to same deployment that copies from trunk_ExtremeSearch/libs/... to .../target/libs.

HTH,
S.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Rohit Bajaj
ID: 39793830
Hi,
I changed the workspace and loaded the project from scratch again as i was unable to resolve the previous issue..
This time i dint get any run time error.
But i got an exception at the line :
new ClassPathXmlApplicationContext("classpath*:spring/root-context.xml");

org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [database.properties] cannot be opened because it does not exist


My root-context.xml :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

	<!-- Root Context: defines shared resources accessible to all other web 
		components -->
	<context:component-scan base-package="com.yatra">
		<context:exclude-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
	</context:component-scan>

	
	<bean id="yatraDB" class="com.yatra.extremesearch.DBTemplate.DBTemplate">
		<constructor-arg index="0" ref="yatraDataSource" />
	</bean>

	<bean id="yatraDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
		destroy-method="close">
		<property name="driverClass" value="${yatra.jdbc.driver}" />
		<property name="jdbcUrl" value="${yatra.jdbc.url}" />
		<property name="user" value="${yatra.jdbc.username}" />
		<property name="password" value="${yatra.jdbc.password}" />
		<property name="acquireIncrement" value="${yatra.acquire.increment}" />
		<property name="minPoolSize" value="${yatra.min.pool.size}" />
		<property name="maxPoolSize" value="${yatra.max.pool.size}" />
		<property name="maxStatementsPerConnection" value="${yatra.max.statements}" />
		<property name="numHelperThreads" value="${yatra.num.helper.threads}" />
		<property name="idleConnectionTestPeriod" value="300" />
		<property name="preferredTestQuery" value="SELECT 0" />
	</bean>
	
	<!-- Define Job beans -->
    <bean id="extremeSearchJob" class="com.yatra.extremesearch.job.ExtremeSearchJob" />
    
     <!-- create the Job -->
    <bean id="extremeSearchJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="extremeSearchJob" />
        <property name="targetMethod" value="execute" />
    </bean>
    
    <!-- create the Trigger with a Schedule -->
    <bean id="extremeSearchJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="extremeSearchJobDetail" />
        <property name="cronExpression" value="0 40 15 * * ? *" />  <!-- Every 5 minutes -->
    </bean>
    
    <bean id="extremeSearchJobTrigger1" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
        <property name="jobDetail" ref="extremeSearchJobDetail" />
		<property name="repeatInterval" value="4000000" />
		<property name="startDelay" value="3000" />
	</bean>
    
    <!-- schedule the Job -->
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    	<property name="triggers">
		    <list>
		    	<ref bean="extremeSearchJobTrigger1"/>
		    </list>
		</property>
		<property name="quartzProperties">  
                <props>  
            <prop key="org.quartz.scheduler.skipUpdateCheck">true</prop>  
          </props>  
     </property> 
    </bean>

	<!-- <bean id="searchService" class="com.yatra.extremesearch.service.impl.SearchParamServiceImpl">
	</bean> -->
	
	<bean id="httpConnectionManagerParams" class="org.apache.commons.httpclient.params.HttpConnectionManagerParams">
		<property name="soTimeout" value="1000000" />
		<property name="connectionTimeout" value="1000000" />
	</bean>

	<bean id="multiThreadedHttpConnectionManager" class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager">
		<property name="params" ref="httpConnectionManagerParams" />
	</bean>


	<bean id="httpClient" class="org.apache.commons.httpclient.HttpClient">
		<constructor-arg index="0" ref="multiThreadedHttpConnectionManager" />
	</bean>

	<bean id="httpService" class="com.yatra.platform.http.HttpService">
		<constructor-arg index="0" ref="httpClient" />
	</bean>

	<import resource="properties.xml" />
	<import resource="thread-pool.xml" />

</beans>
	

Open in new window

0
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 39793849
So  have you verified if  database.properties is available ?
0
 

Author Comment

by:Rohit Bajaj
ID: 39793945
database.properties is present in the path ExtremeSearch\resources\properties\DEV
in my project.
0
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 39793973
Ok , couple of things you need to try here:

1. Copy the file to ExtremeSearch\resources  or/and ExtremeSearch\resources\properties

2 . If (1) does not work , search in your project for the string 'database.properties'  . Obviously , this would have been hardcoded somewhere . Give the full path to the file there
0
 
LVL 6

Expert Comment

by:Mahesh Bhutkar
ID: 39794080
Your spring jars dependency needs to be uptodate along with versions,

I am sharing all required dependency from my project,

antlr-2.7.6.jar
com.springsource.net.sf.cglib-2.2.0.jar
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.log4j-1.2.15.jar
com.springsource.org.aspectj.tools-1.6.6.RELEASE.jar
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
hibernate3.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
javassist-3.12.0.GA.jar
jstl.jar
jta-1.1.jar
mysql-connector-java-5.0.4-bin.jar
org.springframework.aop-3.1.4.RELEASE.jar
org.springframework.asm-3.1.4.RELEASE.jar
org.springframework.aspects-3.1.4.RELEASE.jar
org.springframework.beans-3.1.4.RELEASE.jar
org.springframework.context-3.1.4.RELEASE.jar
org.springframework.context.support-3.1.4.RELEASE.jar
org.springframework.core-3.1.4.RELEASE.jar
org.springframework.expression-3.1.4.RELEASE.jar
org.springframework.jdbc-3.1.4.RELEASE.jar
org.springframework.orm-3.1.4.RELEASE.jar
org.springframework.transaction-3.1.4.RELEASE.jar
org.springframework.web-3.1.4.RELEASE.jar
org.springframework.web.servlet-3.1.4.RELEASE.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
spring-security-config-3.1.3.RELEASE.jar
spring-security-core-3.1.3.RELEASE.jar
spring-security-taglibs-3.1.3.RELEASE.jar
spring-security-web-3.1.3.RELEASE.jar
standard.jar

Probably AOP & Security jars might be not required for you.

Plus you have to add database driver jars like for mysql -> mysql-connector-java-5.0.4-bin.jar, for Oracle -> Ojdbc.jar

Also add your ExtremeSearch\resources folder inside Source Tab of your Java Build Path from properties of the project.

Hope this should resolve all your problems.
0
 

Author Comment

by:Rohit Bajaj
ID: 39805685
I added some jars in the java build path library tab in eclipse. It resolved some of the error.
But i am still getting the following error when i start debug on the following file :

package com.yatra.extremesearch.app;

import org.apache.log4j.Logger;
import org.springframework.context.support.ClassPathXmlApplicationContext;



public class ExtremeSearchApp {
	private static final Logger logger = Logger.getLogger(ExtremeSearchApp.class);
	
	public static void main(String args[]){
		
		 try {
			 logger.info("=====Starting Extreme search======");
			 new ClassPathXmlApplicationContext("classpath*:spring/root-context.xml");
			
			} catch (Exception e) {
				logger.error(e.getMessage());
			}
		}
}

Open in new window




Error :

java.lang.NoClassDefFoundError: src/com/yatra/extremesearch/app/ExtremeSearchApp
Caused by: java.lang.ClassNotFoundException: src.com.yatra.extremesearch.app.ExtremeSearchApp
      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)


Whats the difference between 1) and 2)

1) the classpath which is set in eclipse by selecting Debug configurations
2) adding libraries in java build path by selecting properties of the project.
0
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 39805812
(1)  is where the runtime looks for  classes (during runtime)
(2) is where the compiler looks for classes (during compilation)
0
 
LVL 6

Expert Comment

by:Mahesh Bhutkar
ID: 39814790
Exception indicates that your src/com/yatra/extremesearch/app/ExtremeSearchApp class file not generated.

Check out ExtremeSearchApp.class file is generated or not after compiling classes.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi: barcode reading on android platform 1 96
Problem to Office 1 63
convert Absolute path to relative path of FTP location 7 47
junit initializtion error 2 17
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question