Announcement Announcement Module
Collapse
No announcement yet.
Exception in thread "main" java.lang.NoClassDefFoundError Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception in thread "main" java.lang.NoClassDefFoundError

    Hello everybody. I am writing "hello world" in Java using Spring. So what I did.
    1) The Eclipse EE Indigo has created a new Java Project.
    2) I downloaded spring-framework-3.1.1.RELEASE unpacked into a directory. Have the files in the directory dist (there are many, for some reason I thought that I needed to take a "spring.jar") from org.springframework.aop-sources-3.1.1.RELEASE.jar ending org.springframework.web-sources -3.1.1.RELEASE.jar
    3) I created the four files. The first is the xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="greetingService" class="ua.maybe">
             <property name="greeting" value=" VIZA!" />
    </bean>
    
    
    </beans>
    Second class with void main
    Code:
    package ua;
    
    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.beans.factory.xml.XmlBeanFactory;
    import org.springframework.core.io.FileSystemResource;
    
    public class Full {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		//maybe m=new maybe();
    		//AbstractApplicationContext ctx=FileSystemApplicationText;
    		 BeanFactory factory = new XmlBeanFactory(new FileSystemResource("da.xml"));
    
    		 Maybe greetingService = (Maybe) factory.getBean("greetingService");
    
             greetingService.sayGreeting();
    
    	}
    
    }
    Made another class
    Code:
    package ua;
    
    
    
    public class Maybe implements Gast {
    	 private String greeting;
    	Maybe(){}
    	public void sayGreeting()
    	{
    		System.out.println("Hello Spring! "+greeting);
    		
    	}
        public void setGreeting(String greeting) {
            this.greeting = greeting;
        }
    }
    And the end made interface
    Code:
    package ua;
    
    public interface Gast {
    	void sayGreeting();
    }
    After that, compile the project and get the error. Why is it so?
    Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.<init>(DefaultSingletonBeanRegistry.java:83)
    	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.<init>(FactoryBeanRegistrySupport.java:43)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.<init>(AbstractBeanFactory.java:175)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:157)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:168)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:158)
    	at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:77)
    	at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:66)
    	at ua.Full.main(Full.java:16)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    	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)
    	... 9 more

  • #2
    I would guess that Spring Framework has some dependency on Apache Commons Logging, but the distribution you downloaded only included the Spring Framework and not its dependencies. Browsing http://www.springsource.org/download/community it appears that Spring 3.0.2 was the last release to include its dependencies with the download.

    Comment


    • #3
      Use commons-logging.jar

      use commons-logging.jar to resolve this issue

      Comment

      Working...
      X