I'm working in the development of a custom plugin for sonar which generates a report and exports it to PDF. For that purpose I use one of our libraries with xercesimpl 2.9.1 dependency.
This plugin works with SonarQube 3.7.4 but I'm getting a ClassNotFoundException with SonarQube 4.0 when I analyze a project with "mvn sonar:sonar"
Caused by: java.lang.NoClassDefFoundError: org/apache/xerces/dom/DocumentImpl
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:389)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
at es.excentia.qalitax.report.service.OdtReport.getPdfOutputFile(OdtReport.java:103)
at es.excentia.sonar.odtreports.OdtReportPostJob.generateAndSaveReport(OdtReportPostJob.java:204)
at es.excentia.sonar.odtreports.OdtReportPostJob.executeOnIfLicenseOk(OdtReportPostJob.java:96)
at es.excentia.sonar.licenser.LicensedPostjob.executeOnIfEnabled(LicensedPostjob.java:29)
at es.excentia.sonar.plugins.common.DisableablePostjob.executeOn(DisableablePostjob.java:21)
It seems sonar-plugin-api requires also xercesimpl, but 2.8.1 version, so I have tried some things
- To exclude all xercesimpl dependencies, because since jdk 1.4 xercesimpl is also included -> Wrong. Cast exception obtained.
- To exclude xercesimpl dependency in my package (v2.9.1) and leave just the sonar dependencies (2.8.1). -> Got the same error. Class Not found.
- To exclude xercesimpl dependency in sonar-plugin-api and leave my package's dependency. -> Now the plugin jar includes xercesimpl.jar but I got the same error. I tried to activate "useChildFirstClassLoader" to load xercesimpl 2.9.1 before sonar, but with no luck.
I have read several posts about this, like "Xerces Hell". I also have read that maybe it's a jvm problem , but I have tried it with jdk 6 and 7 with same result.
Any idea?
UPDATE
I did it work copying xercesimpl.jar and xml-apis.jar to the sonar webserver directory: sonarqube-4.0\web\WEB-INF\lib
Is there any way to avoid this?
I tried to modify my pom dependencies to include both libraries in my plugin jar, but when I run the analysis I get the same error.