运行Jenkins插件的JDOM NoClassDefFoundError

时间:2013-02-28 14:50:21

标签: java maven plugins jenkins stack-trace

我正在编写一个使用我自己的jar的Jenkins插件。最后一个需要JDOM。所以,我的POM中有2个依赖项:

  • 我自己使用JDOM的JAR
  • JDOM

它成功构建(mvn clean install),但在运行期间,我遇到了此错误:org.jdom.JDOMException: java.lang.NoClassDefFoundError: org/jdom/Parent

在没有解决方案的情况下询问hereherehere

JDOM jar确实出现在HPI中:WEB-INF\lib\jdom-1.0.jar。我也试过用Tomcat运行Jenkins。而且,我尝试在我的POM中将JDOM配置为mask classes

<build>
  <plugins>
    <plugin>
      <groupId>org.jenkins-ci.tools</groupId>
      <artifactId>maven-hpi-plugin</artifactId>
      <version>1.94</version>
      <configuration>
        <maskClasses>org.jdom.</maskClasses> <!-- HERE -->
        <pluginFirstClassLoader>true</pluginFirstClassLoader>
      </configuration>
    </plugin>
  </plugins>
</build>

没有成功。


我插件的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.jenkins-ci.plugins</groupId>
    <artifactId>plugin</artifactId>
    <version>1.500</version><!-- which version of Jenkins is this plugin built against? -->
  </parent>

  <groupId>***</groupId>
  <artifactId>***</artifactId>
  <version>1.0</version>
  <packaging>hpi</packaging>

  <!-- get every artifact through repo.jenkins-ci.org, which proxies all the artifacts that we need -->
  <repositories>
    <repository>
      <id>repo.jenkins-ci.org</id>
      <url>http://repo.jenkins-ci.org/public/</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>repo.jenkins-ci.org</id>
      <url>http://repo.jenkins-ci.org/public/</url>
    </pluginRepository>
  </pluginRepositories>
  <dependencies>
    <dependency>
      <groupId>com.***</groupId>
      <artifactId>***</artifactId>
      <version>12.2.01</version>
    </dependency>
    <dependency>
        <groupId>jdom</groupId>
        <artifactId>jdom</artifactId>
        <version>1.0</version>
    </dependency>
  </dependencies>
</project>

mvn依赖:分析

[WARNING] Used undeclared dependencies found:
[WARNING]    org.mortbay.jetty:servlet-api:jar:2.5-20081211:test
[WARNING]    commons-lang:commons-lang:jar:2.6:provided
[WARNING]    org.kohsuke.stapler:json-lib:jar:2.1-rev7:provided
[WARNING]    commons-io:commons-io:jar:1.4:provided
[WARNING]    org.jvnet.hudson.dom4j:dom4j:jar:1.6.1-hudson-3:provided
[WARNING]    org.kohsuke.stapler:stapler:jar:1.199:provided
[WARNING] Unused declared dependencies found:
[WARNING]    jdom:jdom:jar:1.0:compile
[WARNING]    org.jenkins-ci.main:jenkins-war:war:1.500:test
[WARNING]    org.jenkins-ci.main:ui-samples-plugin:jar:1.500:test
[WARNING]    javax.servlet:servlet-api:jar:2.4:provided
[WARNING]    org.codehaus.mojo:animal-sniffer-annotations:jar:1.9:provided
[WARNING]    junit:junit:jar:3.8:test

栈跟踪

org.jdom.JDOMException: java.lang.NoClassDefFoundError: org/jdom/Parent: org/jdom/Parent
        at org.jdom.xpath.XPath.newInstance(XPath.java:139)
        at com.***.util.IOFile.scriptBlock(IOFile.java:449)
        at com.***.util.IOFile.scriptBlock(IOFile.java:502)
        at com.***.util.IOFile.createFileFromTemplate(IOFile.java:211)
        at com.***.util.IOFile.createFileFromTemplate(IOFile.java:176)
        at com.***.delivery.task.BuildFromTemplates.execute(BuildFromTemplates.java:89)
        at com.***.delivery.DeliveryThread.integrateSuite(DeliveryThread.java:1586)
        at com.***.delivery.DeliveryThread.run(DeliveryThread.java:363)
        at com.***.pmj.DeliveryBuilder.perform(DeliveryBuilder.java:303)
        at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
        at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:814)
        at hudson.model.Build$BuildExecution.build(Build.java:199)
        at hudson.model.Build$BuildExecution.doRun(Build.java:160)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:593)
        at hudson.model.Run.execute(Run.java:1568)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
        at hudson.model.ResourceController.execute(ResourceController.java:88)
        at hudson.model.Executor.run(Executor.java:237)
Caused by: java.lang.NoClassDefFoundError: org/jdom/Parent
        at org.jaxen.jdom.JDOMXPath.<init>(JDOMXPath.java:91)
        at org.jdom.xpath.JaxenXPath.setXPath(JaxenXPath.java:281)
        at org.jdom.xpath.JaxenXPath.<init>(JaxenXPath.java:99)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.jdom.xpath.XPath.newInstance(XPath.java:129)
        ... 17 more
Caused by: java.lang.ClassNotFoundException: org.jdom.Parent
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at winstone.classLoader.WebappClassLoader.loadClass(WebappClassLoader.java:83)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 25 more
Caused by: java.lang.NoClassDefFoundError: org/jdom/Parent
        at org.jaxen.jdom.JDOMXPath.<init>(JDOMXPath.java:91)
        at org.jdom.xpath.JaxenXPath.setXPath(JaxenXPath.java:281)
        at org.jdom.xpath.JaxenXPath.<init>(JaxenXPath.java:99)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.jdom.xpath.XPath.newInstance(XPath.java:129)
        at com.***.util.IOFile.scriptBlock(IOFile.java:449)
        at com.***.util.IOFile.scriptBlock(IOFile.java:502)
        at com.***.util.IOFile.createFileFromTemplate(IOFile.java:211)
        at com.***.util.IOFile.createFileFromTemplate(IOFile.java:176)
        at com.***.delivery.task.BuildFromTemplates.execute(BuildFromTemplates.java:89)
        at com.***.delivery.DeliveryThread.integrateSuite(DeliveryThread.java:1586)
        at com.***.delivery.DeliveryThread.run(DeliveryThread.java:363)
        at com.***.pmj.DeliveryBuilder.perform(DeliveryBuilder.java:303)
        at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
        at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:814)
        at hudson.model.Build$BuildExecution.build(Build.java:199)
        at hudson.model.Build$BuildExecution.doRun(Build.java:160)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:593)
        at hudson.model.Run.execute(Run.java:1568)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
        at hudson.model.ResourceController.execute(ResourceController.java:88)
        at hudson.model.Executor.run(Executor.java:237)
Caused by: java.lang.ClassNotFoundException: org.jdom.Parent
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at winstone.classLoader.WebappClassLoader.loadClassmaven (WebappClassLoader.java:83)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 25 more
Caused by: java.lang.NoClassDefFoundError: org/jdom/Parent
        at org.jaxen.jdom.JDOMXPath.<init>(JDOMXPath.java:91)
        at org.jdom.xpath.JaxenXPath.setXPath(JaxenXPath.java:281)
        at org.jdom.xpath.JaxenXPath.<init>(JaxenXPath.java:99)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.jdom.xpath.XPath.newInstance(XPath.java:129)
        at com.***.util.IOFile.scriptBlock(IOFile.java:449)
        at com.***.util.IOFile.scriptBlock(IOFile.java:502)
        at com.***.util.IOFile.createFileFromTemplate(IOFile.java:211)
        at com.***.util.IOFile.createFileFromTemplate(IOFile.java:176)
        at com.***.delivery.task.BuildFromTemplates.execute(BuildFromTemplates.java:89)
        at com.***.delivery.DeliveryThread.integrateSuite(DeliveryThread.java:1586)
        at com.***.delivery.DeliveryThread.run(DeliveryThread.java:363)
        at com.***.pmj.DeliveryBuilder.perform(DeliveryBuilder.java:303)
        at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
        at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:814)
        at hudson.model.Build$BuildExecution.build(Build.java:199)
        at hudson.model.Build$BuildExecution.doRun(Build.java:160)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:593)
        at hudson.model.Run.execute(Run.java:1568)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
        at hudson.model.ResourceController.execute(ResourceController.java:88)
        at hudson.model.Executor.run(Executor.java:237)
Caused by: java.lang.ClassNotFoundException: org.jdom.Parent
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at winstone.classLoader.WebappClassLoader.loadClass(WebappClassLoader.java:83)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 25 more

如果您需要更多信息,请在评论中告诉我。谢谢!

1 个答案:

答案 0 :(得分:2)

临时解决方法:

令人惊讶的是,将JDOM JAR jdom-1.0.jar添加到Jenkins库文件夹~\.jenkins\war\WEB-INF\lib\中解决了这个问题!