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.”
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)
Apparently, not even the deployment of Sonar worked. Thus, you have to change your “catalina.sh” 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.
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.