从PMD 5.0.3更新到5.0.5后,我在尝试通过ant运行CPD时收到NoClassDefFoundError。我看到CPD改为使用FilenameUtils,但这应该不是问题,因为我在任务的路径中有commons-io.jar。
这是Ant目标(FilenameUtils在commons-io.jar中)
<target name="cpd" depends="init">
<path id="pmd.cpd.classpath">
<pathelement location="${3rdparty_libdir}/pmd.jar"/>
<pathelement location="${3rdparty_libdir}/asm.jar"/>
<pathelement location="${3rdparty_libdir}/commons-io.jar"/>
<pathelement location="${3rdparty_libdir}/jaxen.jar"/>
</path>
<taskdef name="cpd" classname="net.sourceforge.pmd.cpd.CPDTask" classpathref="pmd.cpd.classpath"/>
<cpd minimumTokenCount="${pmd.cpd.minimumTokenCount}" format="${pmd.cpd.format}"
outputFile="${pmd.cpd.outputFile}" encoding="${pmd.cpd.encoding}">
<fileset dir="${srcdir}">
<include name="**/*.java"/>
</fileset>
</cpd>
</target>
我没有看到任何方法将classpathref放入cpd调用中。
这是错误
java.lang.NoClassDefFoundError: org/apache/commons/io/FilenameUtils
at net.sourceforge.pmd.cpd.CPD.add(CPD.java:100)
at net.sourceforge.pmd.cpd.CPD.add(CPD.java:60)
at net.sourceforge.pmd.cpd.CPDTask.tokenizeFiles(CPDTask.java:119)
at net.sourceforge.pmd.cpd.CPDTask.execute(CPDTask.java:64)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
... snip
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FilenameUtils
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 20 more
答案 0 :(得分:0)
替换:
<path id="pmd.cpd.classpath">
<pathelement location="${3rdparty_libdir}/pmd.jar"/>
<pathelement location="${3rdparty_libdir}/asm.jar"/>
<pathelement location="${3rdparty_libdir}/commons-io.jar"/>
<pathelement location="${3rdparty_libdir}/jaxen.jar"/>
</path>
使用:
<path id="pmd.cpd.classpath">
<fileset dir="${3rdparty_libdir}">
<include name="**/*.jar" />
</fileset>
</path>
{3rdparty_libdir}应该包含pmd,jaxen和commons-io jar。 Asm没有必要。
答案 1 :(得分:0)
我设法使用以下命令行使其工作:
java -Xmx512m -classpath ~/pmd-bin-5.0-2.5/lib/commons-io-2.2.jar:~/pmd-bin-5.0-2.5/lib/asm-3.2.jar:~/pmd-bin-5.0-2.5/lib/jaxen-1.1.1.jar:~/pmd-bin-5.0-2.5/lib/pmd-5.0.5.jar:~/ObjCLanguage-0.0.8-SNAPSHOT.jar net.sourceforge.pmd.cpd.CPD --minimum-tokens 100 --files PATH_TO_XCODE_SOURCE --language ObjectiveC --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer