0
votes

I was trying to run a simple java program in windows by running the command

pmd -d path-to-source\com\vaannila\domain\User.java -f text -R java-basic

and error showing up is as below.

Exception in thread "main" java.lang.NoClassDefFoundError: C:\pmd\pmd-bin-5/4/6\bin//\lib\asm-5/0/4/jar Caused by: java.lang.ClassNotFoundException: C:\pmd\pmd-bin-5.4.6\bin..\lib\asm-5.0.4.jar at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) Could not find the main class: C:\pmd\pmd-bin-5.4.6\bin..\lib\asm-5.0.4.jar. Program will exit.

Please help me with this to run the PMD

1
Looks like there's a typo in the scriptMad Physicist
I'm going to go out on a limb and say that C:\pmd\pmd-bin-5.4.6\bin..\lib\asm-5.0.4.jar should have a slash between bin and ..Mad Physicist
If C:\pmd\pmd-bin-5.4.6\lib\asm-5.0.4.jar exists, you should consider submitting a bug report.Mad Physicist
@MadPhysicist the asm-5.0.4.jar exists and the error is still coming. reporting a bug to?nsuriya239
Have you tried the latest version of PMD (6.6.0)? The version you are using (5.4.6) is more than a year old... -> pmd.github.ioadangel

1 Answers

0
votes

I can't reproduce your problem and I can't exactly make sense of the error message.

According to the error message, you have extracted PMD 5.4.6 into C:\pmd, so that the directory C:\pmd\pmd-bin-5.4.6 exists. Inside this directory, there are two subdirectories: bin - which contains pmd.bat and lib, which contains the necessary jars to be put onto the classpath.

So, without further configuration of your system, you should be able to run simply C:\pmd\pmd-5.4.6\bin\pmd.bat in a command shell - you should see the help screen (and not the NoClassDefFound exception).

Can you try this? Does that work for you? If not -> reinstall PMD as your installation seems to be broken somehow.

I see, that you are calling pmd with just using pmd - this works, if you are currently in the directory C:\pmd\pmd-bin-5.4.6\bin - or if you add this directory to your PATH environment variable. Even if I do this, it works for me, regardless in which directory I'm in.

Did you configure something like the PATH environment variable?

I cannot make sense out of the error message - it claims, it can't find a class named "C:\pmd\pmd-bin-5/4/6\bin//\lib\asm-5/0/4/jar". This is not a class name, it looks like a manipulated class path - and also look at the mix of forward and backward slashes. The next part of the error is "C:\pmd\pmd-bin-5.4.6\bin..\lib\asm-5.0.4.jar" - while it might seem to be right, that there is a slash missing - it still doesn't make sense. The error message said, that it could not find the main class - but the main class is called net.soureforge.pmd.PMD.

For reference, here is the original content of pmd.bat:

@echo off
set TOPDIR=%~dp0..
set OPTS=
set MAIN_CLASS=net.sourceforge.pmd.PMD

java -classpath %TOPDIR%\lib\* %OPTS% %MAIN_CLASS% %*

Can you compare this with your pmd.bat? I suspect, your file looks somehow different.

You can also run PMD without the batch file, e.g.:

java -classpath C:\pmd\pmd-bin-5.4.6\lib\* net.sourceforge.pmd.PMD -d path-to-source\com\vaannila\domain\User.java -f text -R java-basic

Does that work for you?

P.S.: It's true, that PMD 5.4.6 is the last one, that runs on Java 1.6. But that doesn't mean, that newer versions of PMD cannot analyze Java 1.6. code. You would just need a recent java runtime (e.g. java 10 or 11) for executing PMD and a separate JDK for building your project. PMD can analyze any version of java, it doesn't depend on the java version, it is running with.