Have you ever felt like a noob? Well I have . I know you may have the argument that I am actually a noob but this one was hilarious. I will take you through this experience.

I started Java development a while ago after working for more than 6 years with Microsoft technologies. Deployment on a Windows Server is way much easier than a Linux server using terminal commands. You can browse, edit and move around files more conveniently in a Windows server. Not to mention that finding traces and logs for errors are rather more difficult in a Linux environment without a graphical user interface.

I deployed a Java web application on my server a few month ago after learning more about Nginx and Apache Tomcat and how to configure Nginx as a proxy for Tomcat  using some resources that I found searching in google. It was a hassle at first but it didn’t waste much of my time.

Last week I decided to release a beta version of the website I have been working on for a couple of months. Easy at it turned out for the first time. I found a bug and I deployed the war file again for the second time. I assumed it was okay to copy the files to a directory at /path_to_tomcat/webapps and change the configuration in server.xml for tomcat and restarting tomcat service. However, it turned out to be a severe failure. Even the web application I had deployed months ago and never touched since then would shut down for a mysterious reason I couldn’t find out. I looked at the logs for the web application (the first one), everything appeared to be working fine but once the recently deployed application started loading it would cause tomcat to crash.

I asked a couple of my friends who are experience Java developers and Linux users for help as I wasn’t able to find any logs to identify the problem. Meanwhile, I dug a bit deeper for the source of the issue. I found another log for tomcat with the format of catalina.yyyy-MM-dd.log which was my saviour.

tail -f /usr/share/tomcat7/logs/catalina.2012-01-05.log

Using tail for the log file I could see the log insertions in real time.

Jan 5, 2012 12:37:42 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class
org.springframework.web.util.Log4jConfigListener
java.lang.IllegalStateException: Web app root system property already set to different value:
 'webapp.root' =
[/usr/share/tomcat7/webapps/applicationxxx/] instead of [/usr/share/tomcat7/webapps/applicationyyy/] -
 Choose unique
values for the 'webAppRootKey' context-param in your web.xml files!
        at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(WebUtils.java:147)
        at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:117)
        at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:45)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
        at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
        at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:636)

Very strange but I should have set a property for log4j called webAppRootKey inside my web.xml otherwise it would make the application server (tomcat) crash.

<context-param>
<param-name>webAppRootKey</param-name>
<param-value>myapplicationxxx</param-value>
</context-param>

This has to be done for every single application deployed in tomcat to avoid the issues.

These sort of issues also show the importance of automated deployment and continuous integration strategies.