Sonar on Debian with Tomcat 6

After moving all MEDICO related code to Maven2 and adopting a Continuous Integration cycle for it, I decided to take the next step and perform automatic code Monitoring with Sonar. We had been doing code monitoring before with Hudson and different plugins for PMD, Checkstyle etc. But it turned out that accessing the resulting information via the Hudson interface is not convenient if you want to monitor the quality of several software projects over time.

This is where Sonar comes into play. Quoting from their website:

“Sonar enables to collect, analyze and report metrics on source code. Sonar not only offers consolidated reporting on and across projects throughout time, but it becomes the central place to manage code quality.”

Sonar 1238344318231

Since Sonar does not officially support deployment in Tomcat 6, the rest of this post explains how to install Sonar on Debian Linux running Apache Tomcat version 6.0.18 and JDK 1.6.0_07-b06.

1. Preparing the WAR file

Prepare the WAR file accroding to the Sonar Full Installation Guide.

2. Before Deployment

With the standard Tomcat 6 setup you will run into java.lang.OutOfMemoryError Exceptions for the PermGen space. These look like that in the “catalina.<date>.log” file:

SEVERE: An exception or error occurred in the container during the request processing

java.lang.OutOfMemoryError: PermGen space

at java.lang.Throwable.getStackTraceElement(Native Method)

at java.lang.Throwable.getOurStackTrace(

at java.lang.Throwable.printStackTrace(

at java.util.logging.SimpleFormatter.format(

at org.apache.juli.FileHandler.publish(

at java.util.logging.Logger.log(

at java.util.logging.Logger.doLog(

at java.util.logging.Logger.logp(

at org.apache.juli.logging.DirectJDKLog.log(

at org.apache.juli.logging.DirectJDKLog.error(

at org.apache.catalina.core.StandardWrapperValve.invoke(

at org.apache.catalina.core.StandardContextValve.invoke(

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(

at org.apache.catalina.core.StandardHostValve.invoke(

at org.apache.catalina.valves.ErrorReportValve.invoke(

at org.apache.catalina.core.StandardEngineValve.invoke(

at org.apache.catalina.connector.CoyoteAdapter.service(

at org.apache.coyote.ajp.AjpAprProcessor.process(

at org.apache.coyote.ajp.AjpAprProtocol$AjpConnectionHandler.process(



Apparently, not even the deployment of Sonar worked. Thus, you have to change your “” according to this article. Search for the JAVA_OPTS variable and add these parameters:

JAVA_OPTS=”-Dfile.encoding=UTF-8 -server -Xms1536m -Xmx1536m

-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC”

The article cited above also suggests to add “-Djava.awt.headless=true” but that is not applicable for my case since I am running an X-Server on the same machine to perform automated UI tests.

3. Deployment

Now you can deploy your WAR file, e.g., via the Tomcat Manager application or just moving the “sonar.war” file to the webapps directory of you Tomcat installation.

4. Database Setup

After logging into Sonar for the first time, it asks for the Database Setup.

I created just the default integrated database. Performing this step took several seconds, but then Sonar was up and running!

5. First login

Just a hint (I had to look that up): The default password for user “admin” is “admin”.

After changing this password, you might run into 500 Internal Server errors. As Olivier from the Sonar developers pointed out, this is a known issue: SONAR-514. All you have to do is delete all session cookies and login again.

3 Responses to “Sonar on Debian with Tomcat 6”

  1. Olivier Says:

    Hello Manual,

    Great post ! Even if Sonar does not “support officially” Tomcat 6, I think it would be great to have all documentation grouped on the wiki.
    Do you mind that I include it on the installation page ?



  2. SRG Says:

    Sadly, i’ve tried exactly what you say here (with Tomcat 6.0 and last Sonar war) and i still have all the time “java.lang.OutOfMemoryError: PermGen space” …
    I really wonder if this appear due to the poor technical choices made by sonar dev’ (jruby, hibernate, … what a mess)

  3. Praveen Sdhu Says:

    HI Team,

    I have installed sonar 2.8 and build/deployed sonar.war on my tomcat, all looks good!

    The below steps does not work not sure how deployed war has reference to sonar.home

    1) Stop the tomcat
    2) Rename c:\Dev\sonar-2.8 to c:\Dev\sonar-2.8-bk
    3) Start the tomcat and try to access /sonar on localhost but application cannot be accessed?

    Why deployed war has reference to Sonar installation directory?

    All the above mentioned is to trouble shoot when I copied sonar.war to our new Linux box for which application failed to start.

Leave a Reply