Spring boot CLI refuses to run on Git bash window. I've added it to path in windows and works from cmd. The error in git bash is:
$ spring
Error: Could not find or load main class org.springframework.boot.loader.JarLauncher
The problem occurs because when attempting to run the Spring Boot CLI jar the script is using both a malformed file path for JAVA_HOME and for the Classpath. When looking at the bin directory of the spring installation you can see two scripts:
spring
spring.bat
The spring.bat script is executed when you run from the windows CMD and will work fine, however when running in git bash it will use the spring script. This script will attempt to correct the issue by using cygpath
to ensure that the file paths are in a unix format. It does this only when it determines that it is running in a Cygwin environment, but does not make this determination when running from the git bash. As a result the file paths become malformed.
Fortunately there is a hack that can resolve this issue if you are interested. Comment out the if
statement at line 17 through 19 and the add its contents as a separate line like so:
# if $cygwin ; then
# [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
# fi
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
And again for another if
statement at line 92:
# if $cygwin; then
# SPRING_HOME=`cygpath --path --mixed "$SPRING_HOME"`
# CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# fi
SPRING_HOME=`cygpath --path --mixed "$SPRING_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
You will now be able to run the Spring Boot CLI from git bash.
I had the same issue while running the "spring" command in git bash, I found that my spring was installed on D drive(while Java was installed on C drive). When running the "spring" command in git bash on C drive directory, I would get the above error. If I switch the directory to D drive in git bash and run the "spring" command again, it would work.