问题
I know it's recurent question but I couldn't find a solution to my issue.
In JENKINS, I run a SONAR analysis after the build. When Soanar gets to Java bytecode scan...
it displays : WARN - Class '.../.../.../...' is not accessible through the ClassLoader
.
The scan is on a Maven project, and Sonar keeps displayin this message throw many other classes that uses Maven dependancies.
The Sonar analysis is using the SONAR-RUNNER.
I saw in many posts, that the issue could be fixed by adding sonar.librairies=/path/to/libraries/*jar
in the sonar-project.properties
but with Maven , dependancies are not grouped under one folder. Jar's are dispatched under different folders under the maven-repositories.
So how can I fix this issue to scan my code without these warnings ?
FYI :
Jenkins 1.555
Sonar 4.2
Sonar Runner 2.3
Java 1.7
Maven 3.04
Stack Trace :
09:23:55.605 INFO - Java bytecode scan...
09:23:55.646 WARN - Class 'org/springframework/context/ApplicationContext' is not accessible through the ClassLoader.
09:23:55.656 WARN - Class 'com/mongodb/MongoClient' is not accessible through the ClassLoader.
09:23:55.657 WARN - Class 'com/mongodb/DB' is not accessible through the ClassLoader.
09:23:55.661 WARN - Class 'org/springframework/context/ApplicationContext' is not accessible through the ClassLoader.
09:23:55.662 WARN - Class 'org/springframework/context/ApplicationContext' is not accessible through the ClassLoader.
...
09:23:55.749 WARN - Class 'org/apache/log4j/Logger' is not accessible through the ClassLoader.
09:23:55.773 INFO - Java bytecode scan done: 168 ms
Edit :
Running mvn dependency:tree
in jenkins build :
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli)
[INFO] +- org.springframework:spring-context:jar:4.0.3.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:4.0.3.RELEASE:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | +- org.springframework:spring-beans:jar:4.0.3.RELEASE:compile
[INFO] | +- org.springframework:spring-core:jar:4.0.3.RELEASE:compile
[INFO] | | \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] | \- org.springframework:spring-expression:jar:4.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.0.3.RELEASE:compile
[INFO] | \- org.springframework:spring-web:jar:4.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-test:jar:4.0.3.RELEASE:test
[INFO] +- org.apache.poi:poi:jar:3.9:compile
[INFO] | \- commons-codec:commons-codec:jar:1.5:compile
...
...
[INFO] +- org.mockito:mockito-all:jar:1.9.5:test
[INFO] +- com.jayway.jsonpath:json-path:jar:0.9.1:test
[INFO] | \- net.minidev:json-smart:jar:1.2:test
[INFO] +- org.hamcrest:hamcrest-all:jar:1.3:test
[INFO] \- junit:junit:jar:4.11:test (scope not updated to compile)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Thanks
回答1:
Since Maven lists the missing classes, you're probably using the Jenkins plugin to run Sonar. I never used this plugin but my guess is that it doesn't know about Maven. Therefore, it can't create a classpath from the POM and the classes are really missing when it runs.
Try to run Sonar using the Maven goal: mvn sonar:sonar
after configuring the Sonar plugin for Maven correctly.
来源:https://stackoverflow.com/questions/23754871/class-xxx-xxx-xxx-is-not-accessible-through-the-classloader-warning-in-sonar