Compiling with ANT - namespace problem - sonar not bound

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • what are you trying to achieve
  • what have you tried so far to achieve this

Using SonarQube 8.5.1.38104
Trying to compile Juliet Test Cases and run Sonar with ANT build file to compare with SpotBugs
I have followed the examples, but the namespace function does appear to work

Here is my ANT build file (note I removed the first less than bracket because it was not showing up on post):

project name=“My Project” default=“war” basedir="." xmlns:sonar=“antlib:org.sonar.ant”>

Java TestCases Build File

 <property name="sonar.host.url" value="http://localhost:8080" /> 
 <property name="sonar.projectKey" value="org.sonarqube:sonarqube-scanner-ant" />
 <property name="sonar.projectName" value="Example of SonarScanner for Ant Usage" />
 <property name="sonar.projectVersion" value="1.0" />
 <property name="sonar.sources" value="src" />
 <property name="sonar.java.binaries" value="build" />
 <property name="sonar.java.libraries" value="lib/*.jar" />
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
<!-- Compile everything in this directory -->
<javac includeantruntime="false"
  srcdir="${src}" 
  destdir="${build}"
  debug="true"
  debuglevel="lines,vars,source"
  fork="true"
  memoryinitialsize="1024m"
  memorymaximumsize="1024m"> 
  <classpath refid="project.classpath"/>
  <include name="testcases/${parentdir.basename}/${basedir.basename}/*"/>
</javac>
<!-- Execute SonarScanner for Ant Analysis -->
<sonar:sonar />

It keeps telling me that prefix “sonar” for element “sonar” is not bound. But, I thought that was the very first line in the project definition.

C:\Users\leona\Documents\Juliet_Test_Suite_v1.3_for_Java\Java\src\testcases\CWE80_XSS\s01\build.xml:114: The prefix “sonar” for element “sonar:sonar” is not bound.
at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:293)
at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:182)
at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:104)
at org.apache.tools.ant.Main.runBuild(Main.java:802)
at org.apache.tools.ant.Main.startAnt(Main.java:223)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
Caused by: org.xml.sax.SAXParseException; systemId: file:/C:/Users/leona/Documents/Juliet_Test_Suite_v1.3_for_Java/Java/src/testcases/CWE80_XSS/s01/build.xml; lineNumber: 114; columnNumber: 20; The prefix “sonar” for element “sonar:sonar” is not bound.
at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:178)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:284)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2710)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:534)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:888)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:824)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216)
at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:635)
at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:280)
… 6 more

Total time: 0 seconds

C:\Users\leona\Documents\Juliet_Test_Suite_v1.3_for_Java\Java\src\testcases\CWE80_XSS\s01>

I am new to SonarQube, new to Ant, new to Maven. It is a school project I am working on.

Any help would be appreciated!

Cheers,
Len.

After much reading and editing, I got the code to work.