<?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>
上面的蚂蚁脚本我试图运行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脚本中遗漏了一些内容。
答案 0 :(得分:1)
将 pmd.home \ lib 中的所有文件复制到 ant.home \ lib 文件夹
pmd.home是你的pmd目录:在你的情况下: D:\ Software \ Java \ pmd-4.2.5 ant.home是你的主目录:假设你正在使用netbeans,它将是 netbeans \ java \ ant
注意重复的罐子或重复的版本(特别是蚂蚁)。
然后再次运行该命令。 希望有所帮助。
答案 1 :(得分:1)
在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!
答案 2 :(得分:0)
我想将<!--pathelement location="${PMD.home}/lib/jaxen-1.1.1.jar" -->
更改为<pathelement location="${PMD.home}/lib/jaxen-1.1.1.jar" />
可以解决问题吗?或者你的所有libs都已加载?请尝试ant -verbose
。
答案 3 :(得分:0)
我有完全相同的问题,版本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>
希望这有帮助!