Why the built jar of sonar-xml plugin contains javax.xml.* packages?

I built sonar-xml from source by its latest tag 2.7.0.3820 (mvn clean package), I found that the final jar sonar-xml-plugin-2.7.0-SNAPSHOT.jar contains classes for package javax.xml. Even more, I decompiled javax.xml.xpath.XPathFactoryFinder.class, and the method _newFacotry will look for class org.apache.xpath.jaxp.XPathFactoryImpl as a last try, which is different from jdk’s behavior above java8, in jdk _newFactory will return com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl.

Are those classes under javax.xml added by maven plugin sonar-packaging-maven-plugin? why not use those classes from jdk?


Update:

I mimic this behavior in a test project, the final jar built by jdk8 contains javax.xml.xpath.XPathFactoryFinder.class which will return org.apache.xpath.jaxp.XPathFactoryImpl. You can run this jar with java -Djaxp.debug app.jar and the output is:

JAXP: using thread context class loader (sun.misc.Launcher$AppClassLoader@33909752) for search
JAXP: Looking up system property 'javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom'
JAXP: The property is undefined.
JAXP: found null in $java.home/jaxp.properties
JAXP: attempting to use the platform default W3C DOM XPath lib
JAXP: factory 'com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl' was found for http://java.sun.com/jaxp/xpath/dom
Hello World!

It seems that adding classes that conflict with jdk have no influence. So why add them in the first place?

Hi @sify21,

sonar-xml does not have javax.xml.* packages, it comes from its dependencies.

$ mvn dependency:tree -Dscope=compile
org.sonarsource.xml:sonar-xml-plugin:sonar-plugin:2.11.0-SNAPSHOT
+- org.sonarsource.analyzer-commons:sonar-analyzer-commons:jar:2.7.0.1482:compile
+- org.sonarsource.api.plugin:sonar-plugin-api:jar:10.1.0.809:provided
+- org.slf4j:slf4j-api:jar:1.7.30:provided
+- com.google.code.findbugs:jsr305:jar:3.0.2:provided
\- org.sonarsource.analyzer-commons:sonar-xml-parsing:jar:2.7.0.1482:compile
   +- xerces:xercesImpl:jar:2.12.2:compile
   +- xml-apis:xml-apis:jar:1.4.01:compile
   \- com.fasterxml.woodstox:woodstox-core:jar:6.4.0:compile
      \- org.codehaus.woodstox:stax2-api:jar:4.2.1:compile

In the above list of dependencies, only xml-apis:xml-apis:jar:1.4.01 has classes in the javax.xml. package. So java-xml has javax.xml.* classes, because it depends on xerces:xercesImpl:jar:2.12.2 which depends on xml-apis.

You should ask the maintainers of xerces why they depend on xml-apis which has JVM javax.xml.* packages.
What problem do you face because of this?