Maven error in MINGW Git bash: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher

Viewed 1672

I'm aware of the fact that this issue has been discussed in several questions but no answer solved my specific issue.

I have installed Git bash and Maven and I'm trying to execute Maven with Git bash. It aborts with the mentioned error.

My system environment:

Windows 7
Git 2.13.3
Maven 3.5.0

The required user variables:

HOME=%HOMEPATH%
M3_HOME=%MAVEN_HOME%
MAVEN_HOME=path-with-no-blanks
Path=%MAVEN_HOME%\bin

Maven works fine on Windows command prompt and Cygwin. Only MINGW-based Git bash fails.

I examined the bash script mvn under: C:\path\to\maven\bin

By setting log outputs and by checking when MAVEN_HOME value gets lost I found out that it gets cleared by these statements (even JAVA_HOME):

# For MinGW, ensure paths are in Unix format before anything is touched !!!HERE MAVEN_HOME value is getting lost!!!
if $mingw ; then
  [ -n "$MAVEN_HOME" ] &&
    MAVEN_HOME=`(cd "$MAVEN_HOME"; pwd)`
  [ -n "$JAVA_HOME" ] &&
    JAVA_HOME=`(cd "$JAVA_HOME"; pwd)`
  # TODO classpath?
fi

On another Windows machine (different version of Maven and Git) the same lines are a bit different:

M2_HOME="`(cd "$MAVEN_HOME"; pwd)`"

instead of:

MAVEN_HOME=`(cd "$MAVEN_HOME"; pwd)`

First, I thought it's due to the kind of quotation characters. But the working Windows machine even runs well with the new script from my failing Windows machine. I also tried to install the old Git or an older Maven - nothing helps.

Why does the mentioned bash script line clears the MAVEN_HOME variable?

2 Answers

Experiencing exactly the same problem on a Windows 7 machine. Happened overnight with no version change in git/mingw64, maven or java.

The first test you can consider is a PATH issue (the OP actually mention an incorrect Path=%MAVEN_HOME%\bin)

Use, for testing, a simplified PATH in a CMD session (so just limited to that session)

set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%MAVEN_HOME%\bin;%PATH%
set PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin;%PATH%

You can adapt the same idea in your .bashrc, if you want a similar $PATH in your bash session, by typing bash in the CMD with a simplified PATH.

Then; in that context, you can check again if the issue persists.

Related