views:

6776

answers:

5

hi.. i am executing simple Dependency Injection program of spring & getting this exception. I have already included common-logging1.1.1.jar and spring.jar file. Could you please help to out?

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:119)
    at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:55)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:56)
    at com.client.StoryReader.main(StoryReader.java:15)
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)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 6 more
A: 

Try doing a complete clean of the target/deployment directory for the app to get rid of any stale library jars. Make a fresh build and check that commons-logging.jar is actually being placed in the correct lib folder. It might not be included when you are building the library for the application.

emills
A: 

I have already included common-logging1.1.1.jar and ...

Are you sure you spelled the name of the JAR file exactly right? I think it should probably be common-logging-1.1.1.jar (note the extra - in the name). Also check if the directory name is correct.

NoClassDefFoundError always means that a class cannot be found, so most likely your class path is not correct.

Jesper
`NoClassDefFoundError` can also be caused by other corner cases, like when class initializers fail in obscure circumstances.
skaffman
Yes, but 99.9% of the time it's caused by class path errors.
Jesper
Furthermore, if he gets a NoClassDefFoundError because the class instantiation failed, then he should have gotten a ExceptionInInitializerError exception first (unless of course it was caught silently).
Kolibri
A: 

Just check whether the commons-logging.jar has been added to your libs and the classpath.. I had the same issue and that was because of this. dhammikas-

dhammikas
A: 

hi..where does the target folder stored in the computer. i am not aware of it. can you please tell me that?

Sneha
FYI: It looks like you may be responding to someone's answer. If so, you should probably make this a comment on their answer rather than creating your own, separate answer. By making this a comment on their answer, the person will be notified of the comment. By making a separate answer, the person may not know that you are asking a question. :)
Adam Paynter
A: 

I generally assign the classpath to a variable and then verify it. I've written a small ruby script which I include in a my startup scripts which validates the classpath before launching java. Validating the classpath before the JVM starts has saved me lots of time troubleshooting these types of problems.

brianegge