How to run sonarqube for apache tomcat

I am trying to analyze the code smells of apache tomcat with sonarqube for my university project. I have installed sonarqube community version. I couldn’t run it for apache tomcat. Please help me with the procedure that how can I configure sonarcube for apache tomcat.



Welcome to SonarSource Community! :sonarsource:

Please review our documentation SonarQube Documentation | SonarQube Docs for more information, especially the

For your project, here are the instructions:

  • Download apache tomcat locally (I think you are using this repo GitHub - apache/tomcat: Apache Tomcat)
  • Read through the documents and BUILDING.txt to understand how to build the project.
  • Make sure you can build the project by following its instructions
  • Download Sonar Scanner for Ant
    • You need to use this scanner since Tomcat uses Ant to build the project
  • Follow our Sonar Scanner for Ant documentation and run ant in the root directory of Tomcat:
    ant sonar -Dsonar.login=yourAuthenticationToken

Please let me know if you have further questions.


1 Like


I realize now that there may be a better way to incorporate Sonar scanner analysis into your Ant script: exec the vanilla Sonar scanner instead of using the Sonar scanner for Ant.

Please let me know your thoughts on this.


Hi, Thanks a lot for your help. I was able to successfully build the Tomcat but when I was ant sonar -Dsonar.login=yourAuthenticationToken; it says Build failed, target sonar doesn’t exist.

I have attached a few screen-shorts:
When I gave the mentioned command, it shows the build failed:

using the documentation the tomcat was successfully build:

sonarqube is up with server:

how can I solve the problem?


Target "sonar" does not exist .. means this is missing in your build.xml

<target name="sonar">

see Targets and Extension-Points


To be able to use

<!-- Execute SonarScanner for Ant Analysis -->
    <sonar:sonar />

the namespace has to be declared in <project/>

<project name="Foobar" xmlns:sonar="antlib:org.sonar.ant">

sonarqube-ant-task-*.jar for the sonar ant scanner has to be in sight for ant
The most simple way is to start your ant scripts via bat file like that

set ANT_HOME=c:\tools\apache-ant-1.10.12
set ANT_ARGS=-lib c:\tools\ant_extralibs
set JAVA_HOME=c:\Program Files\JavaSoft\JDK\1.8.0_201
set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin;%PATH%

:: default
ant -f %1

:: debug
:: ant -debug -f %1

when the ant_extralibs folder has all the additional ant tasks like i.e. sonarqube-ant-task, antcontrib,
xmltask, ant-flaka … etc.
Then you don’t need the taskdef as given in the example snippet of the sonarqube scanner for ant documentation.

    <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
        <!-- Update the following line, or put the "sonarqube-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
        <classpath path="path/to/sonar/ant/task/lib/sonarqube-ant-task-*.jar" />



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.