Install Sonar Service
-
set JAVA_HOME=/usr/lib/jvm/default-java
(optional); -
install database:
apt-get install mysql-server
; -
download sonar-3.5.1.zip and extract to /opt/sonar-server;
-
test startup:
$SONAR_HOME/bin/linux-x86-32/sonar.sh console
, web browser: http://localhost:9000; -
build database: root@chadpc56:/opt/sonar-server/sonar-3.5.1/extras/database/mysql#
mysql -u root -p < create_database.sql
; -
modify db config: comment out "sonar.jdbc.url: jdbc:h2...", uncomment "sonar.jdbc.url: jdbc:mysql..." in $SONAR_SERVER/conf/sonar.properties;
-
verify db operations:
$SONAR_HOME/bin/linux-x86-32/sonar.sh console
, you can see many tables are created in mysql db, thenmysqlshow sonar -u sonar -p
, with password "sonar", you can see a list of tables created; -
start sonar service:
nohup $SONAR_HOME/bin/linux-x86-32/sonar.sh start 1>/dev/null &
, you can monitor its startup viatail -f $SONAR_HOME/logs/sonar.log
;
Note: If using zsh, you have to add disown %1
to detach background job from current shell, or your background jobs will be killed when you logged out, even it was nohupped. (or you can add "setopt nohup" in .zshrc to the same effect).
First Login Configuration
- login http://localhost:9000 with admin/admin;
Analyse Java Project with Sonar Runner
-
Installing and Configuring Sonar Runner: download, extract, set environment variables, add to path, modify config file, verify (sonar-runner -h);
-
Analyzing with Sonar Runner: create sonar-project.properties under project root folder, run sonar runner at project root folder (sonar-runner), see result in sonar dashboard;
Note: add sonar.login & sonar.password in sonar-project.properties;
Analyse Java Project with Ant Task
Build a Demo Java Project
-
apt-get install ant;
-
copy junit-4.11.jar and hamcrest-core-1.3.jar to lib folder of ant(/usr/share/ant/lib);
-
create build.xml:
Run Sonar
-
Download sonar-ant-task-2.1.jar;
-
Add sonar tasks into above build.xml;
-
Run sonar with
ant sonar
;