• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1583
  • Last Modified:

java.lang.NoClassDefFoundError

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
Rohit Bajaj
Asked:
Rohit Bajaj
  • 4
  • 3
  • 2
  • +1
1 Solution
 
SurranoSystem EngineerCommented:
the spelling looks ok but doublecheck.
What is your classpath? Does it include spring api? Which version?
0
 
Rohit BajajAuthor Commented:
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
 
SurranoSystem EngineerCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Rohit BajajAuthor Commented:
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
 
Sharon SethCommented:
So  have you verified if  database.properties is available ?
0
 
Rohit BajajAuthor Commented:
database.properties is present in the path ExtremeSearch\resources\properties\DEV
in my project.
0
 
Sharon SethCommented:
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
 
Mahesh BhutkarCommented:
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
 
Rohit BajajAuthor Commented:
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
 
Sharon SethCommented:
(1)  is where the runtime looks for  classes (during runtime)
(2) is where the compiler looks for classes (during compilation)
0
 
Mahesh BhutkarCommented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now