I've been using Maven on Git Bash (64-bit) for a few months now, and suddenly it stopped working, and is now generating this error on any maven command:
myuser@mypc MINGW64 ~ (master *)
$ mvn -v
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
I have reviewed many questions on SO, including this one: Maven error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher but have not solved my problem.
I have upgraded to the latest Git for Windows (2.14.2.windows.2) from 2.12 but the problem remains.
My Maven installation is at C:\apache-maven-3.5.0\bin, which is in my PATH variable:
myuser@mypc MINGW64 ~ (master *)
$ echo $PATH
...:/c/jdk1.7.0_79/bin:/c/apache-maven-3.5.0/bin:...
I also have JAVA_HOME set correctly:
myuser@mypc MINGW64 ~ (master *)
$ echo $JAVA_HOME
C:\jdk1.7.0_79
I've tried adding/removing MAVEN_HOME but that doesn't seem to be detected in the Apache Maven Startup Script (C:\apache-maven-3.5.0\bin\mvn) :
myuser@mypc MINGW64 ~ (master *)
$ echo $MAVEN_HOME
c:\apache-maven-3.5.0
If I go into the Apache Maven Startup Script and replace instances of ${MAVEN_HOME} with C:\apache-maven-3.5.0, then it seems to find the Launcher class and executes correctly.
Edits like this:
CLASSWORLDS_JAR=`echo "${MAVEN_HOME}"/boot/plexus-classworlds-*.jar`
to
CLASSWORLDS_JAR=`echo /c/apache-maven-3.5.0/boot/plexus-classworlds-*.jar`
then produce:
myuser@mypc MINGW64 ~ (master *)
$ mvn -v
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T15:39:06-04:00)
Maven home: C:\apache-maven-3.5.0
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: C:\jdk1.7.0_79\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
This is an inelegant workaround, and would rather find the proper solution. What environment or configuration changes can I try that would allow Maven to run without hardcoding the path?
Steps/results for VonC's answer:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\windows\system32>set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\windows\system32>set GH=C:\Program Files\Git
C:\windows\system32>set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%
C:\windows\system32>set PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin;%PATH%
C:\windows\system32>echo %PATH%
C:\jdk1.7.0_79\bin;c:\apache-maven-3.5.0\bin;C:\Program Files\Git\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\windows\system32>echo %M2_HOME%
C:\apache-maven-3.5.0
C:\windows\system32>mvn -v
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T15:39:06-04:00)
Maven home: c:\apache-maven-3.5.0\bin\..
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: C:\jdk1.7.0_79\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
C:\Windows\System32>bash
myuser@mypc MINGW64 /c/Windows/System32
$ mvn -v
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
myuser@mypc MINGW64 /c/Windows/System32
$ echo $M2_HOME
C:\apache-maven-3.5.0
S279887@P2025774 MINGW64 /c/Windows/System32
$ echo $MAVEN_HOME
c:\apache-maven-3.5.0
After further debugging, I realized my problem appears to be identical to Maven error in MINGW Git bash: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher, where the MAVEN_HOME variable gets cleared in this section of code:
# For MinGW, ensure paths are in Unix format before anything is touched
if $mingw ; then
[ -n "$MAVEN_HOME" ] &&
MAVEN_HOME=`(cd "$MAVEN_HOME"; pwd)`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`(cd "$JAVA_HOME"; pwd)`
# TODO classpath?
fi
If I run the offending line [[ -n "$MAVEN_HOME" ]] && MAVEN_HOME=`(cd "$MAVEN_HOME"; pwd)`
in a bash session, I can reproduce the behavior in the latest Git for Windows:
myuser@mypc MINGW64 ~ (master *)
$ git --version
git version 2.14.2.windows.3
myuser@mypc MINGW64 ~ (master *)
$ echo $MAVEN_HOME
c:\apache-maven-3.5.0
myuser@mypc MINGW64 ~ (master *)
$ [[ -n "$MAVEN_HOME" ]] && MAVEN_HOME=`(cd "$MAVEN_HOME"; pwd)`
myuser@mypc MINGW64 ~ (master *)
$ echo $MAVEN_HOME
myuser@mypc MINGW64 ~ (master *)
$
This is what I get when I execute the command directly -- it returns the current directory and not MAVEN_HOME as I would expect. Assuming that happens because the command executes in a subshell?
myuser@mypc MINGW64 ~ (master *)
$ echo `(cd "$MAVEN_HOME"; pwd)`
/c/home
myuser@mypc MINGW64 ~ (master *)
$ `(cd "$MAVEN_HOME"; pwd)`
bash: /c/home: Is a directory
The first thing to test is the %PATH%
: in a CMD session, set up a simplified PATH
.
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;%PATH%
Note how the C:\WINDOWS\...
paths are kept at the end of the PATH: that is important.
Then prepend the path of your %JAVA_HOME%\bin
, and of <maven>\bin
.
And make sure to set M2_HOME
to C:\apache-maven-3.5.0
.
Finally, test your mvn
command, both in the current CMD, or (in that same Windows) in a git bash session (typing just "bash
")
Finally, depending on your program and your brand of OS, don't forget that with Windows 10 you now have WSL and a full-fledge Linux bash. That can be a possible alternative.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With