Search code examples
pmd

How to run PMD in bash


I'm currently trying to run PMD on git bash with the command "run.sh pmd -d -f -R" but I get an error saying 'Could not find or load main class net.sourceforge.pmd.PMD'. I've tried setting the classpath in the environment variable but still get the error. Does anyone know what the problem is ?


Solution

  • This seems to be a bug in the PMD run.sh script. It supports the cygwin environment, but the git bash environment doesn't seem to be a vanilla cygwin environment (although all required cygwin commands are there).

    The script builds up the classpath. Since it runs under a cygwin-like environment, the classpath looks like "/c/pmd-bin-5.5.4/lib/pmd-core-5.5.4.jar:...". However, the Java Runtime runs under Windows (and not cygwin), so the path needs to be translated into "C:\pmd-bin-5.5.4\lib\pmd-core-5.5.4.jar;...". Note, that the Windows notation of paths are used (the drive letter and semicolon as path separator).

    The script uses the uname command, to determine, whether it runs under a cygwin-like environment. It only checks for "CYGWIN". But git bash uses e.g. "MINGW64_NT-10.0".

    There is the new issue #305 now, it should be fixed soon.

    You can manually fix the script bin/run.sh, by changing the function is_cygwin to:

    is_cygwin() {
        case "$(uname)" in
            CYGWIN*|MINGW*)  # look also for MINGW!!
                readonly cygwin=true
                ;;
        esac
        # OS specific support.  $var _must_ be set to either true or false.
        if [ -z ${cygwin} ] ; then
            readonly cygwin=false
        fi
    }