1

我正在尝试使用 sonar-ws-client 插件。但是当我运行mvn sonar:sonar得到错误

[FATAL ERROR] org.sonar.maven.SonarMojo#execute() caused a linkage error (java.l
ang.NoClassDefFoundError) and may be out-of-date. Check the realms:
[FATAL ERROR] Plugin realm = app0.child-container[org.codehaus.sonar:sonar-maven
-plugin:3.1.1]
urls[0] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/sonar/sonar-maven
-plugin/3.1.1/sonar-maven-plugin-3.1.1.jar
urls[1] = file:/C:/Users/Renjith.R/.m2/repository/org/apache/maven/shared/maven-
dependency-tree/1.2/maven-dependency-tree-1.2.jar
urls[2] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/plexus/plexus-uti
ls/1.1/plexus-utils-1.1.jar
urls[3] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/sonar/sonar-batch
/3.1.1/sonar-batch-3.1.1.jar
urls[4] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/sonar/sonar-core/
3.1.1/sonar-core-3.1.1.jar
urls[5] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/sonar/sonar-plugi
n-api/3.1.1/sonar-plugin-api-3.1.1.jar
urls[6] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/sonar/sonar-check
-api/3.1.1/sonar-check-api-3.1.1.jar
urls[7] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/sonar/sonar-color
izer/3.1.1/sonar-colorizer-3.1.1.jar
urls[8] = file:/C:/Users/Renjith.R/.m2/repository/commons-io/commons-io/2.0.1/co
mmons-io-2.0.1.jar
urls[9] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/sonar/sonar-chann
el/3.1.1/sonar-channel-3.1.1.jar
urls[10] = file:/C:/Users/Renjith.R/.m2/repository/org/slf4j/slf4j-api/1.6.2/slf
4j-api-1.6.2.jar
urls[11] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/sonar/sonar-dupl
ications/3.1.1/sonar-duplications-3.1.1.jar
urls[12] = file:/C:/Users/Renjith.R/.m2/repository/com/google/guava/guava/10.0.1
/guava-10.0.1.jar
urls[13] = file:/C:/Users/Renjith.R/.m2/repository/com/google/code/findbugs/jsr3
05/1.3.9/jsr305-1.3.9.jar
urls[14] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/sonar/sonar-grap
h/3.1.1/sonar-graph-3.1.1.jar
urls[15] = file:/C:/Users/Renjith.R/.m2/repository/commons-lang/commons-lang/2.6
/commons-lang-2.6.jar
urls[16] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/sonar/sonar-squi
d/3.1.1/sonar-squid-3.1.1.jar
urls[17] = file:/C:/Users/Renjith.R/.m2/repository/org/picocontainer/picocontain
er/2.14.1/picocontainer-2.14.1.jar
urls[18] = file:/C:/Users/Renjith.R/.m2/repository/org/hibernate/hibernate-annot
ations/3.4.0.GA/hibernate-annotations-3.4.0.GA.jar
urls[19] = file:/C:/Users/Renjith.R/.m2/repository/org/hibernate/ejb3-persistenc
e/1.0.2.GA/ejb3-persistence-1.0.2.GA.jar
urls[20] = file:/C:/Users/Renjith.R/.m2/repository/org/hibernate/hibernate-commo
ns-annotations/3.1.0.GA/hibernate-commons-annotations-3.1.0.GA.jar
urls[21] = file:/C:/Users/Renjith.R/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1
.jar
urls[22] = file:/C:/Users/Renjith.R/.m2/repository/xml-apis/xml-apis/1.3.03/xml-
apis-1.3.03.jar
urls[23] = file:/C:/Users/Renjith.R/.m2/repository/commons-configuration/commons
-configuration/1.6/commons-configuration-1.6.jar
urls[24] = file:/C:/Users/Renjith.R/.m2/repository/commons-collections/commons-c
ollections/3.2.1/commons-collections-3.2.1.jar
urls[25] = file:/C:/Users/Renjith.R/.m2/repository/commons-digester/commons-dige
ster/1.8/commons-digester-1.8.jar
urls[26] = file:/C:/Users/Renjith.R/.m2/repository/commons-beanutils/commons-bea
nutils/1.8.3/commons-beanutils-1.8.3.jar
urls[27] = file:/C:/Users/Renjith.R/.m2/repository/commons-codec/commons-codec/1
.4/commons-codec-1.4.jar
urls[28] = file:/C:/Users/Renjith.R/.m2/repository/jfree/jfreechart/1.0.9/jfreec
hart-1.0.9.jar
urls[29] = file:/C:/Users/Renjith.R/.m2/repository/jfree/jcommon/1.0.12/jcommon-
1.0.12.jar
urls[30] = file:/C:/Users/Renjith.R/.m2/repository/org/slf4j/jcl-over-slf4j/1.6.
2/jcl-over-slf4j-1.6.2.jar
urls[31] = file:/C:/Users/Renjith.R/.m2/repository/org/slf4j/log4j-over-slf4j/1.
6.2/log4j-over-slf4j-1.6.2.jar
urls[32] = file:/C:/Users/Renjith.R/.m2/repository/com/thoughtworks/xstream/xstr
eam/1.3.1/xstream-1.3.1.jar
urls[33] = file:/C:/Users/Renjith.R/.m2/repository/xpp3/xpp3/1.1.3.3/xpp3-1.1.3.
3.jar
urls[34] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/woodstox/woodsto
x-core-lgpl/4.0.4/woodstox-core-lgpl-4.0.4.jar
urls[35] = file:/C:/Users/Renjith.R/.m2/repository/stax/stax-api/1.0.1/stax-api-
1.0.1.jar
urls[36] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/woodstox/stax2-a
pi/3.0.1/stax2-api-3.0.1.jar
urls[37] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/staxmate/staxmat
e/2.0.0/staxmate-2.0.0.jar
urls[38] = file:/C:/Users/Renjith.R/.m2/repository/xerces/xercesImpl/2.8.1/xerce
sImpl-2.8.1.jar
urls[39] = file:/C:/Users/Renjith.R/.m2/repository/xalan/xalan/2.7.1/xalan-2.7.1
.jar
urls[40] = file:/C:/Users/Renjith.R/.m2/repository/xalan/serializer/2.7.1/serial
izer-2.7.1.jar
urls[41] = file:/C:/Users/Renjith.R/.m2/repository/org/mybatis/mybatis/3.0.6/myb
atis-3.0.6.jar
urls[42] = file:/C:/Users/Renjith.R/.m2/repository/org/apache/derby/derby/10.7.1
.1/derby-10.7.1.1.jar
urls[43] = file:/C:/Users/Renjith.R/.m2/repository/org/apache/derby/derbyclient/
10.7.1.1/derbyclient-10.7.1.1.jar
urls[44] = file:/C:/Users/Renjith.R/.m2/repository/org/apache/derby/derbynet/10.
7.1.1/derbynet-10.7.1.1.jar
urls[45] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/sonar/sonar-upda
te-center-common/1.1/sonar-update-center-common-1.1.jar
urls[46] = file:/C:/Users/Renjith.R/.m2/repository/org/hibernate/hibernate-core/
3.3.2.GA/hibernate-core-3.3.2.GA.jar
urls[47] = file:/C:/Users/Renjith.R/.m2/repository/antlr/antlr/2.7.6/antlr-2.7.6
.jar
urls[48] = file:/C:/Users/Renjith.R/.m2/repository/org/hibernate/hibernate-entit
ymanager/3.4.0.GA/hibernate-entitymanager-3.4.0.GA.jar
urls[49] = file:/C:/Users/Renjith.R/.m2/repository/javassist/javassist/3.4.GA/ja
vassist-3.4.GA.jar
urls[50] = file:/C:/Users/Renjith.R/.m2/repository/geronimo-spec/geronimo-spec-j
ta/1.0-M1/geronimo-spec-jta-1.0-M1.jar
urls[51] = file:/C:/Users/Renjith.R/.m2/repository/org/hibernate/hibernate-ehcac
he/3.3.2.GA/hibernate-ehcache-3.3.2.GA.jar
urls[52] = file:/C:/Users/Renjith.R/.m2/repository/net/sf/ehcache/ehcache/1.2.3/
ehcache-1.2.3.jar
urls[53] = file:/C:/Users/Renjith.R/.m2/repository/commons-dbcp/commons-dbcp/1.3
/commons-dbcp-1.3.jar
urls[54] = file:/C:/Users/Renjith.R/.m2/repository/commons-pool/commons-pool/1.5
.4/commons-pool-1.5.4.jar
urls[55] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/plexus/plexus-cl
assworlds/2.2.3/plexus-classworlds-2.2.3.jar
urls[56] = file:/C:/Users/Renjith.R/.m2/repository/ch/qos/logback/logback-classi
c/0.9.30/logback-classic-0.9.30.jar
urls[57] = file:/C:/Users/Renjith.R/.m2/repository/ch/qos/logback/logback-core/0
.9.30/logback-core-0.9.30.jar
urls[58] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/sonar/sonar-depr
ecated/3.1.1/sonar-deprecated-3.1.1.jar
urls[59] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/sonar/sonar-java
-api/3.1.1/sonar-java-api-3.1.1.jar
[FATAL ERROR] Container realm = plexus.core
urls[0] = file:/D:/Maven/apache-maven-2.2.1/lib/maven-2.2.1-uber.jar
[FATAL ERROR] org.codehaus.mojo.sonar.SonarMojo#execute() caused a linkage error
 (java.lang.NoClassDefFoundError) and may be out-of-date. Check the realms:
[FATAL ERROR] Plugin realm = app0.child-container[org.codehaus.mojo:sonar-maven-
plugin:1.0]
urls[0] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/mojo/sonar-maven-
plugin/1.0/sonar-maven-plugin-1.0.jar
urls[1] = file:/C:/Users/Renjith.R/.m2/repository/org/codehaus/plexus/plexus-uti
ls/1.4.1/plexus-utils-1.4.1.jar
[FATAL ERROR] Container realm = plexus.core
urls[0] = file:/D:/Maven/apache-maven-2.2.1/lib/maven-2.2.1-uber.jar
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] org/sonar/wsclient/services/Query
org.sonar.wsclient.services.Query
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.NoClassDefFoundError: org/sonar/wsclient/services/Query
        at java.lang.Class.getDeclaredFields0(Native Method)
        at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
        at java.lang.Class.getDeclaredFields(Class.java:1743)
        at org.picocontainer.injectors.AdaptingInjection$2.run(AdaptingInjection
.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.picocontainer.injectors.AdaptingInjection.injectionFieldAnnotated
(AdaptingInjection.java:209)
        at org.picocontainer.injectors.AdaptingInjection.fieldAnnotatedInjection
Adapter(AdaptingInjection.java:188)
        at org.picocontainer.injectors.AdaptingInjection.createComponentAdapter(
AdaptingInjection.java:57)
        at org.picocontainer.behaviors.AbstractBehaviorFactory.createComponentAd
apter(AbstractBehaviorFactory.java:44)
        at org.picocontainer.behaviors.OptInCaching.createComponentAdapter(OptIn
Caching.java:45)
        at org.picocontainer.DefaultPicoContainer.addComponent(DefaultPicoContai
ner.java:536)
        at org.picocontainer.DefaultPicoContainer.access$300(DefaultPicoContaine
r.java:80)
        at org.picocontainer.DefaultPicoContainer$AsPropertiesPicoContainer.addC
omponent(DefaultPicoContainer.java:1142)
        at org.sonar.api.platform.ComponentContainer.addComponent(ComponentConta
iner.java:92)
        at org.sonar.api.platform.ComponentContainer.addSingleton(ComponentConta
iner.java:84)
        at org.sonar.batch.bootstrap.Module.addCoreSingleton(Module.java:115)
        at org.sonar.batch.bootstrap.ProjectExtensionInstaller.installExtension(
ProjectExtensionInstaller.java:86)
        at org.sonar.batch.bootstrap.ProjectExtensionInstaller.install(ProjectEx
tensionInstaller.java:59)
        at org.sonar.batch.bootstrap.ProjectModule.addProjectPluginExtensions(Pr
ojectModule.java:109)
        at org.sonar.batch.bootstrap.ProjectModule.configure(ProjectModule.java:
60)
        at org.sonar.batch.bootstrap.Module.init(Module.java:49)
        at org.sonar.batch.bootstrap.Module.installChild(Module.java:70)
        at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:113)
        at org.sonar.batch.bootstrap.BatchModule.doStart(BatchModule.java:105)
        at org.sonar.batch.bootstrap.Module.start(Module.java:83)
        at org.sonar.batch.bootstrap.BootstrapModule.doStart(BootstrapModule.jav
a:111)
        at org.sonar.batch.bootstrap.Module.start(Module.java:83)
        at org.sonar.batch.bootstrapper.Batch.startBatch(Batch.java:73)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:60)
        at org.sonar.maven.SonarMojo.execute(SonarMojo.java:150)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
nManager.java:490)
        at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:98)
        at org.codehaus.mojo.sonar.Bootstraper.start(Bootstraper.java:79)
        at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:88)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
nManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:694)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandalone
Goal(DefaultLifecycleExecutor.java:569)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
ltLifecycleExecutor.java:539)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
dleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
ts(DefaultLifecycleExecutor.java:284)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
fecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:6
0)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: java.lang.ClassNotFoundException: org.sonar.wsclient.services.Query
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(
SelfFirstStrategy.java:50)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm
.java:244)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm
.java:230)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        ... 53 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23 seconds
[INFO] Finished at: Wed Mar 20 10:51:22 IST 2013
[INFO] Final Memory: 23M/42M
[INFO] ------------------------------------------------------------------------

这是我正在使用的java代码。

import org.sonar.wsclient.Sonar;
import org.sonar.wsclient.services.Measure;
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;

public class SampleWsClien{
    Measure i=getProjectMeasure("ncloc");

    public org.sonar.wsclient.services.Measure getProjectMeasure(String metricKey) {
        Sonar sonar = Sonar.create("http://localhost:9000");    
        Resource resource = sonar.find(ResourceQuery.createForMetrics("com.hp.curator:curator", metricKey));
            return resource.getMeasure(metricKey);
    }
}

在我的 pom.xml 中,我将 ws-client 的依赖项添加为

   <dependency>
      <groupId>org.codehaus.sonar</groupId>
      <artifactId>sonar-ws-client</artifactId>
      <version>${sonar.version}</version>
    </dependency>

    <dependency>
      <groupId>commons-httpclient</groupId>
      <artifactId>commons-httpclient</artifactId>
      <version>3.1</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
4

1 回答 1

0

如果我的理解是正确的,您正在尝试对使用 sonar-ws-client 作为依赖项的项目进行 SonarQube 分析(使用 SonarQube 服务器 3.1.1),可能版本与 3.1.1 不同。理论上应该没有影响,但 Maven 2 在插件和项目类加载器的隔离方面确实存在问题。有时项目依赖项会在插件类加载器中泄漏。

解决方案:使用 Maven 3。

于 2013-09-11T07:58:54.033 回答