Category Archives: Tomcat web server

java.lang.IllegalStateException: Web app root system property already set to different value: ‘webapp.root’ = [/ApplicationPath1] instead of [/ApplicationPath2] – Choose unique values for the ‘webAppRootKey’ context-param in your web.xml files!

Recently I have deployed two J2EE web application in tomcat web server. Both application uses the log4j. Tomcat server is up and running with no issues.

But at regular interval, one of the J2EE web application was going down. I was digging into the logs and google to find the solution. At regular times, it made us to enter into the tomcat manager page to start the application manually which was down.

Then I have identified the following exception message

java.lang.IllegalStateException: Web app root system property already set to different value: 'webapp.root' = [C:\Program Files\Apache Software Foundation\Tomcat7.0.57\webapps\application1\] instead of [C:\Program Files\Apache Software Foundation\Tomcat7.0.57\webapps\application2\] - Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(
at org.springframework.web.util.Log4jWebConfigurer.initLogging(
at org.springframework.web.util.Log4jConfigListener.contextInitialized(
at org.apache.catalina.core.StandardContext.listenerStart(
at org.apache.catalina.core.StandardContext.startInternal(
at org.apache.catalina.util.LifecycleBase.start(
at org.apache.catalina.core.ContainerBase.addChildInternal(
at org.apache.catalina.core.ContainerBase.addChild(
at org.apache.catalina.core.StandardHost.addChild(
at org.apache.catalina.startup.HostConfig.deployDirectory(
at org.apache.catalina.startup.HostConfig$
at java.util.concurrent.Executors$ Source)
at Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$ Source)
at Source)

Root cause:

Due to the business requirement, we copied the application1’s code base and created the application2’s code base.
I gave unique names wherever necessary in the configuration files. But still I encountered the above error message. After spending long time, I got the below information about the spring framework

“WARNING: Some containers (like Tomcat) do not keep system properties separate per web app. You have to use unique “webAppRootKey” context-params per web app then, to avoid clashes. Other containers like Resin do isolate each web app’s system properties: Here you can use the default key (i.e. no “webAppRootKey” context-param at all) without worrying. ”

It turns out that the webAppRootKey is a Spring context parameter. It exposes the web application’s root directory as a system property. So, it is the value of the webAppRootKey that provides the name for the system property to use. That’s fine if you’ve just got one webapp in Tomcat. Spring will just choose a default value for this (app.root) and off you go. However, as the warning above notes, Tomcat does not keep system properties separate per webApp. This means that when we get to the second application, the same system property (app.root) is being set to a new value (our second application’s root directory, rather than the first!)

The reason this is occurring at all is that Log4JConfigListener is trying to set the webAppRootKey in both cases. This allows log4J to place log and config files in directories relative to the application root directory, rather than in a fixed path.

I decided the easiest thing was just to use a non-default name for the webAppRootKey for each of my applications.

That is, I fixed this by placing the following context-parameter into each of the web application’s web.xml files:


This fixed the problem

java.lang.NoClassDefFoundError: Lorg/apache/commons/logging/Log;

Caused by: java.lang.NoClassDefFoundError: Lorg/apache/commons/logging/Log;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Unknown Source)
at java.lang.Class.getDeclaredFields(Unknown Source)
at org.apache.catalina.util.Introspection.getDeclaredFields(
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(
at org.apache.catalina.startup.ContextConfig.configureStart(
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(
at org.apache.catalina.core.StandardContext.startInternal(
at org.apache.catalina.util.LifecycleBase.start(
... 6 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.Log
at org.apache.catalina.loader.WebappClassLoader.loadClass(
at org.apache.catalina.loader.WebappClassLoader.loadClass(
... 20 more


Adding the commons-logging.jar to the class path will solve the problem.

Download the same from

Happy Learning 🙂

SEVERE: Servlet /Spring3HibernateApp threw load() exception java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

I was working on the Spring MVC example. When I deployed my Spring web application into the Apache Tomcat 7 server, I end up with the following exception

Oct 12, 2014 8:24:01 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /Spring3HibernateApp threw load() exception
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(
at org.apache.catalina.loader.WebappClassLoader.loadClass(
at org.apache.catalina.core.DefaultInstanceManager.loadClass(
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(
at org.apache.catalina.core.DefaultInstanceManager.newInstance(
at org.apache.catalina.core.StandardWrapper.loadServlet(
at org.apache.catalina.core.StandardWrapper.load(
at org.apache.catalina.core.StandardContext.loadOnStartup(
at org.apache.catalina.core.StandardContext.startInternal(
at org.apache.catalina.util.LifecycleBase.start(
at org.apache.catalina.core.ContainerBase$
at org.apache.catalina.core.ContainerBase$
at Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$ Source)
at Source)


ClassNotFoundException should always makes you to think “JAR is missing”. That is, the eclipse could not able to locate the class file ‘DispatcherServlet” here. The ClassNotFoundException clearly indicates that you are missing org.springframework.web.servlet classes.

So make sure the Spring MVC JAR files is available in the classpath. The Spring JARs and all their dependencies should be in your /WEB-INF/lib.

Add all JAR files in the Project build path, which is, Right-click on Project -> Properties -> Java Build Path -> Libraries. Add all external JARS as like either user library or web app libraries. Click on “Add External JARs” to add all the JAR files.

Even after this, if the exception occurs, try the below instructions

1) Project Properties -> Deployment Assembly
2) Add -> Java Build Path Entries
3) You should now see the list of libraries on your build path that you can specify for inclusion into your finished WAR.
4) Select the ones you want and hit Finish.

Happy Learning 🙂

Java Web Start Application fails: connection refused exception when trying to run a jar via Java web start

I wrote my first Java Web Start application. Here as follows,

Step 1: My simple Hello World Swing java program

package com.saravanansivaji.swing;

import java.awt.EventQueue;
import javax.swing.JFrame;

public class HelloWorldSwing extends JFrame {

public HelloWorldSwing() {

setTitle("Hello World example");
setSize(300, 200);

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {
public void run() {
HelloWorldSwing ex = new HelloWorldSwing();

Step 2: I packed this as executable JAR file, myswing.jar

Step 3: Created a web application folder “apps” under Tomcat Server web application directory “webapps”.


Step 4: Created a JNLP (Java Network Launch Protocol) file in the web folder “apps”, myswing.jnlp,

<?xml version=”1.0″ encoding=”utf-8″?>

<jnlp spec=”0.2 1.0″

<title>Welcome to Swing World</title>
<vendor>Saravanan Sivaji</vendor>
<homepage href=”index.html”/>
<description>Hello Swing World</description>
<icon href=”saravanansivaji.JPEG”/>

<j2se version=”1.5+”/>
<jar href=”myswing.jar”/>

<application-desc main-class=”com.saravanansivaji.swing.HelloWorldSwing”/>


Step 5: Create an index page that invokes JNLP file


<TITLE> New Document </TITLE>

<a href=”myswing.jnlp”>Run Swing Master</a>

So finally, my tomcat web folder “apps” contains the following files
1) a JAR file to launch
2) a JNLP file to invoke JAR
3) a index.html file to invoke JNLP file

Now running the tomcat web server and hitting the browser with URL

http://localhost:8080/apps/ Connection refused: connect
at Method)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at com.sun.javaws.jnl.LaunchDescFactory.buildDescriptor(Unknown Source)
at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$ Source)
at Source)

The issue occurred, my tomcat web server was running on 8081 port. But I had hit on localhost:8080 port.

Java web start application was launched the HelloWorldSwing component successfully.

Happy ending 🙂

How to change the Tomcat webserver default port

Sometimes there will be a requirement to change the default port number of Tomcat web server over which it runs.

So how to change? Very simple!!

Locate the server.xml file in the tomcat installation directory. It will be available at {Tomcat Installation home directory}\conf folder.

For example,

Here is my tomcat installation directory is E:\J2EE\apache-tomcat-6.0.18. server.xml file can be located at E:\J2EE\apache-tomcat-6.0.18\conf\server.xml

Now, open the server.xml and search for the similar lines,

<Connector port="8081” protocol=”HTTP/1.1″
redirectPort=”8443″ />

Here the above lines states, Tomcat server runs on 8081 port.

So if from browser, if we hit as http://localhost:8081/, we can see the Tomcat server’s default page.

For example, the below instruction tells Tomcat server to run on port 8282,

<Connector port="8282” protocol=”HTTP/1.1″
redirectPort=”8443″ />

Happy ending!! 🙂