2

I am new to Google App Engine. I am getting this error :

java.lang.NoClassDefFoundError: Could not initialize class 
                  org.apache.commons.logging.LogFactory at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:282) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at 
org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548) at 
org.mortbay.jetty.servlet.Context.startContext(Context.java:136) at ...

I have added slf4j dependencies and excluded commons-logging in spring-context dependency but still getting this error. The app works perfectly fine on my local machine but gives me this error when deployed to the App Engine.

2 Answers 2

2

Thanks to this blog , I was able to resolve this issue :

Commons-logging is a dependency of many frameworks, Spring included. On the local server, everything runs fine. In the cloud, Google App Engine infrastructure replaces the commons-logging-1.1.1.jar with a JAR of its own that has a different package structure. In effect, that means you get funny NoClassDefFoundError on org.apache.commons.logging.LogFactory even though you included the JAR as a dependency. The solution is to still include the classes, but to give the JAR another name.

Since I use Maven, I removed the commons-logging dependency from the WAR with the exclusion tag for Spring and MyFaces artifact. Then, I added a dependency on commons-logging:commons-logging-api:1.1:jar with the runtime scope. This jar won’t be replaced.

So you should exclude commons-logging from Spring :

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${org.springframework.version}</version>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
    

Then add a dependency on commons-logging-1.1 with runtime scope:

<dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging-api</artifactId>
        <version>1.1</version>
        <scope>runtime</scope>
</dependency>
Sign up to request clarification or add additional context in comments.

Comments

0

You are missing a required jar in your /war/WEB-INF/lib/ folder. It's not enough to have it in your classpath.

If you use Eclipse, you should see a warning in the Problems tab. Right click on it, Quick Fix, select " Copy ...". Or add this jar to the /lib folder manually.

2 Comments

That was the first thing I checked since I got that error. The jar file was available in WEB-INF/lib folder.
It may be another jar which this jar depends on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.