Results 1 to 2 of 2

Thread: Beginner Question: Caused by: java.lang.ClassNotFoundException: org.apache.commons.l

  1. #1
    Join Date
    Oct 2011
    Posts
    1

    Default Beginner Question: Caused by: java.lang.ClassNotFoundException: org.apache.commons.l

    [CODE]Hi,

    Beginner question here and i'm not sure this is the right forum for it.

    I'm starting to learn spring now (using the Manning Spring IN Action text).

    I created a new Spring Project and copied their first example in the book, which is a real simple one below.

    However, I get the exception below.

    Some possible issues I saw that haven't verified yet:

    1. I should be creating a different type of project
    2. It cannot find the knights.xml
    3. Apache is not installed correctly..does it even require it??


    Thanks in Advance



    Code:
    package com.springinaction.knights;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.beans.BeansException;
    
    
    public class KnightMain {
    
    	public static void main(String[] args) {
    		
    		ApplicationContext context = new ClassPathXmlApplicationContext("knights.xml");
    
    		Knight knight = (Knight) context.getBean("knight");
    		knight.embarkQuest();
    	}
    	
    }
    Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    	at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:160)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:89)
    	at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:59)
    	at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:61)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:136)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    	at com.springinaction.knights.KnightMain.main(KnightMain.java:12)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    	... 7 more

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Well what does the struck trace tell you.. The class isn't there, add the class... I.e. add commons-logging... (I strongly suggest you use maven/ant+ivy/gradle to manage your dependencies.).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •