After updating from PMD 5.0.3 to 5.0.5, I am getting a NoClassDefFoundError when trying to run CPD via ant. I see that CPD changed to use FilenameUtils, but that should not be a problem as I have commons-io.jar in the path for the task.
Here is the Ant target (FilenameUtils is in 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>
I don't see any way to put the classpathref in the cpd call.
Here is the error
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
Replace:
With:
{3rdparty_libdir} should contain pmd, jaxen and commons-io jars. Asm isn't necessary.