Pmd ant 脚本给出 java.lang.NoClassDefFoundError: org/jaxen/JaxenException

发布于 2024-12-05 07:30:01 字数 3659 浏览 2 评论 0原文

<?xml version="1.0" encoding="UTF-8"?>
<project name="Example" default="pmd" basedir=".">
<property name="PMD.home" location="D:\Software\Java\pmd-4.2.5"/>
<path id="PMD.lib"> 
    <fileset dir="${PMD.home}\lib"> 
            <include name="*.jar" /> 
    </fileset> 
    <!--pathelement location="${PMD.home}/lib/jaxen-1.1.1.jar" -->
</path> 
<echo>${PMD.home}\lib</echo>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" > 
    <classpath refid="PMD.lib" /> 
</taskdef> 
<target name="pmd">
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="PMD.lib"    />       
<echo>${PMD.home}\bin\pmd-rules.xml</echo>
<pmd> 
<ruleset>${PMD.home}\bin\pmd-rules.xml</ruleset>
<formatter type="html" toFile="pmd_report_ant9.html"  />
<fileset dir="C:\Documents and Settings\twarsi\eclipse3_5\tw1\Example">
<include name="**\*.java"/>
 </fileset>
 </pmd>
</target>
</project>

我试图运行上面的 ant 脚本来执行 PMD 规则集 pmd-rules.xml 但出现以下错误。

 pmd:
 [echo] D:\Software\Java\pmd-4.2.5\bin\pmd-rules.xml
  [pmd] Using the normal ClassLoader
  [pmd] Adding classpath entry: <D:\Software\Java\pmd-4.2.5\bin>
  [pmd] Sending a report to file = D:\Software\Java\pmd-4.2.5\bin\pmd_report
  _ant9.html; renderer = html

 BUILD FAILED
 java.lang.NoClassDefFoundError: org/jaxen/JaxenException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    at java.lang.Class.getConstructor0(Class.java:2699)
    at java.lang.Class.newInstance0(Class.java:326)
    at java.lang.Class.newInstance(Class.java:308)
    at net.sourceforge.pmd.RuleSetFactory.parseSingleRuleNode(RuleSetFactory
  .java:309)
    at net.sourceforge.pmd.RuleSetFactory.parseRuleNode(RuleSetFactory.java:
 253)
    at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.ja
 va:209)
    at net.sourceforge.pmd.RuleSetFactory.createSingleRuleSet(RuleSetFactory
.java:135)
    at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java
:85)
    at net.sourceforge.pmd.ant.PMDTask.doTask(PMDTask.java:220)
    at net.sourceforge.pmd.ant.PMDTask.execute(PMDTask.java:334)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    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.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    at org.apache.tools.ant.Main.runBuild(Main.java:758)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

你能让我知道我缺少什么吗?即使 jaxen-1.1.1.jar 也存在于 lib 目录中。但它显示错误。我是否在 ant 脚本中缺少某些内容。

<?xml version="1.0" encoding="UTF-8"?>
<project name="Example" default="pmd" basedir=".">
<property name="PMD.home" location="D:\Software\Java\pmd-4.2.5"/>
<path id="PMD.lib"> 
    <fileset dir="${PMD.home}\lib"> 
            <include name="*.jar" /> 
    </fileset> 
    <!--pathelement location="${PMD.home}/lib/jaxen-1.1.1.jar" -->
</path> 
<echo>${PMD.home}\lib</echo>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" > 
    <classpath refid="PMD.lib" /> 
</taskdef> 
<target name="pmd">
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="PMD.lib"    />       
<echo>${PMD.home}\bin\pmd-rules.xml</echo>
<pmd> 
<ruleset>${PMD.home}\bin\pmd-rules.xml</ruleset>
<formatter type="html" toFile="pmd_report_ant9.html"  />
<fileset dir="C:\Documents and Settings\twarsi\eclipse3_5\tw1\Example">
<include name="**\*.java"/>
 </fileset>
 </pmd>
</target>
</project>

The above ant script i am trying to run to execute PMD ruleset pmd-rules.xml but i am getting the below error.

 pmd:
 [echo] D:\Software\Java\pmd-4.2.5\bin\pmd-rules.xml
  [pmd] Using the normal ClassLoader
  [pmd] Adding classpath entry: <D:\Software\Java\pmd-4.2.5\bin>
  [pmd] Sending a report to file = D:\Software\Java\pmd-4.2.5\bin\pmd_report
  _ant9.html; renderer = html

 BUILD FAILED
 java.lang.NoClassDefFoundError: org/jaxen/JaxenException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    at java.lang.Class.getConstructor0(Class.java:2699)
    at java.lang.Class.newInstance0(Class.java:326)
    at java.lang.Class.newInstance(Class.java:308)
    at net.sourceforge.pmd.RuleSetFactory.parseSingleRuleNode(RuleSetFactory
  .java:309)
    at net.sourceforge.pmd.RuleSetFactory.parseRuleNode(RuleSetFactory.java:
 253)
    at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.ja
 va:209)
    at net.sourceforge.pmd.RuleSetFactory.createSingleRuleSet(RuleSetFactory
.java:135)
    at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java
:85)
    at net.sourceforge.pmd.ant.PMDTask.doTask(PMDTask.java:220)
    at net.sourceforge.pmd.ant.PMDTask.execute(PMDTask.java:334)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    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.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    at org.apache.tools.ant.Main.runBuild(Main.java:758)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

Can you please let me know what i have missing . Even jaxen-1.1.1.jar is there in lib directory.But it is showing error.Am i missing something in ant script.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半窗疏影 2024-12-12 07:30:01

pmd.home\lib 中的所有文件复制到 ant.home\lib 文件夹

pmd.home 是您的 pmd 目录:在您的情况下:D:\软件\Java\pmd-4.2.5
ant.home 是你的 ant 主目录:假设你使用的是 netbeans,它将是 netbeans\java\ant

注意重复的 jar 或重复的版本(尤其是 ant)。

然后,再次运行该命令。
希望有帮助。

Copy all the files in your pmd.home\lib to ant.home\lib folder

pmd.home is your pmd directory:In your case: D:\Software\Java\pmd-4.2.5
ant.home is your ant home directory: Assuming you are using netbeans, it will be netbeans\java\ant

Watch out for duplicate jars or duplicate versions(especially ant).

And then, run the command again.
Hope that helps.

昔日梦未散 2024-12-12 07:30:01

在 pmd 5.0.3 中,这对我有用:

<property name="pmd.dir" value="${otherSoftware}/pmd-5.0.3" />
<path id="pmd.classpath">
    <fileset dir="${pmd.dir}\lib"> 
        <include name="*.jar" /> 
    </fileset>
</path>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.classpath" />
<taskdef name="cpd" classname="net.sourceforge.pmd.cpd.CPDTask" classpathref="pmd.classpath" />

注意:pmd-5.0.3/lib 包含 jaxen.jar!

In pmd 5.0.3, this works for me:

<property name="pmd.dir" value="${otherSoftware}/pmd-5.0.3" />
<path id="pmd.classpath">
    <fileset dir="${pmd.dir}\lib"> 
        <include name="*.jar" /> 
    </fileset>
</path>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.classpath" />
<taskdef name="cpd" classname="net.sourceforge.pmd.cpd.CPDTask" classpathref="pmd.classpath" />

Note: pmd-5.0.3/lib contains the jaxen.jar!

时光沙漏 2024-12-12 07:30:01

我想将 更改为 可以吗?或者你所有的库都已经加载了吗?请尝试 ant -verbose

I guess changing <!--pathelement location="${PMD.home}/lib/jaxen-1.1.1.jar" --> to <pathelement location="${PMD.home}/lib/jaxen-1.1.1.jar" /> will do the trick? Or are all your libs already loaded? Please try ant -verbose.

千纸鹤 2024-12-12 07:30:01

我在 4.2.6 版本中遇到了完全相同的问题。 jaxen JAR 文件位于 ant 查找 PMD 特定 JAR 文件的目录中似乎很重要。对我来说,以下工作有效,其中所有(四个)PMD jar 文件都位于 ${pmd.home} 中。

<property name="pmd.home" value="../../external/pmd" />
<target name="pmd">
    <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpath="${pmd.home}/pmd-4.2.6.jar"/> 

    <pmd shortFilenames="true">
        <ruleset>basic</ruleset>
        <formatter type="xml" toFile="${report.dir}/pmd.xml"/>
        <fileset dir="${src.dir}">
            <include name="**/*.java"/>
        </fileset>
    </pmd>
</target>

希望这有帮助!

I had the exact same issues, with version 4.2.6. It appears to be important that the jaxen JAR file is in the directory where ant looks for the PMD specific JAR files. For me the following works, where all (four) PMD jar files are located in ${pmd.home}.

<property name="pmd.home" value="../../external/pmd" />
<target name="pmd">
    <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpath="${pmd.home}/pmd-4.2.6.jar"/> 

    <pmd shortFilenames="true">
        <ruleset>basic</ruleset>
        <formatter type="xml" toFile="${report.dir}/pmd.xml"/>
        <fileset dir="${src.dir}">
            <include name="**/*.java"/>
        </fileset>
    </pmd>
</target>

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文