Setting up Sonar

Sonar is great tool for static code analysis. This is a quick how to guide on setting up sonar..
Prerequisites, make sure you have Java SDK installed.

(1) Download sonar from sonar

(2) Unzip the the zip to a folder of your choice.

(3) In the how to for sonar, they advice you use mysql as the database – which is a good advice, but if you just want to use the derby database provided out of the box, the derby database is good enough.

Useful tip to save you some time, I want to setup my sonar server on different host to where the build system is. If you also want to do this, then you need to go to the conf folder,

Edit the file: sonar.properties

and uncomment the line

# uncomment to accept connections from remote hosts. Ba default it only accepts localhost connections.
sonar.derby.drda.host: 0.0.0.0

by uncommenting the above line you allow clients on other boxes to connect to the derby database.

Next startup sonar by going to bin\windows-x86-32 (or the appropriate folder for the OS you are using) and run “StartSonar.bat” ( if you plan to run sonar as a service, it’s worthwhile running the InstallNTService.bat so that Sonar appears in your windows service list). If it’s the first time you starting sonar, you have to be a little patient as it creates the database under the data folder in sonar. To see what’s happening, can tail the log file under logs directory.

You should lots of activity in the sonar.log file and hopefully when sonar is up and running, you will see see lines appearing in your log.


2011.06.11 17:51:11 INFO org.sonar.INFO Register quality models…
2011.06.11 17:51:11 INFO org.sonar.INFO Register quality models done: 2 ms
2011.06.11 17:51:11 INFO org.sonar.INFO Start services done: 18139 ms
2011.06.11 17:51:11 INFO org.sonar.INFO Loading web services…
2011.06.11 17:51:11 INFO org.sonar.INFO Loading web services…
2011.06.11 17:51:12 INFO org.sonar.INFO Sonar started: http://0.0.0.0:9000/

That’s a good sign! 🙂 You should now be able to browse to the sonar page on port 9000 and see something like the following..

Congratulations you have sonar up and running!

Obviously not very exciting, in the next post, I will go through how to to do static analysis of an existing maven project using sonar. Stay tuned!

5 Replies to “Setting up Sonar”

Leave a Reply

Your email address will not be published. Required fields are marked *