Maven error in MINGW Git bash: Could not find or l

2019-04-04 05:20发布

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条回答
倾城 Initia
2楼-- · 2019-04-04 05:21

I was getting the exact same error for a while until I realized that it was being cause by my antivirus (Comodo). Git bash would not work properly even if I had exited/disabled Comodo.

So if you have Comodo, try following these steps to fix the error (if you don't then maybe try performing something similar with whatever antivirus/firewall you are using):

  1. Comodo->Settings->File Rating-> Add Folder (Git Folder). This ended up adding over 5000 trusted files (but it helped fix the issue).

  2. Comodo->Settings->Advanced Protection->Miscellaneous-> and find the checkmark "Don't detect shellcode injections in...". I added the entire Git Folder to shellcode injections.

  3. I set the git folder to "ignore" in Comodo->Settings->containment->"Auto-containment"

I'll add that I'm not sure if all of the steps are required, so feel free to perform them one by one and see which helps.

查看更多
家丑人穷心不美
3楼-- · 2019-04-04 05:32

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.

查看更多
登录 后发表回答