mirror of https://github.com/apache/maven.git
[MNG-7195] Rework JAVA_HOME handling
Dramatically simplify/rework handling by leaving setting JAVA_HOME to the user and try to load java(1) command from it. Technically Maven itself does not require JAVA_HOME to be set. If not set, use java(1) command from PATH on both Windows and POSIX-like systems. This closes #514
This commit is contained in:
parent
6c67c9d0a6
commit
a21be1d231
|
@ -22,7 +22,7 @@
|
||||||
#
|
#
|
||||||
# Environment Variable Prerequisites
|
# Environment Variable Prerequisites
|
||||||
#
|
#
|
||||||
# JAVA_HOME Must point at your Java Development Kit installation.
|
# JAVA_HOME (Optional) Points to a Java installation.
|
||||||
# MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
|
# MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
|
||||||
# MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
|
# MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
|
||||||
# MAVEN_DEBUG_ADDRESS (Optional) Set the debug address. Default value is localhost:8000
|
# MAVEN_DEBUG_ADDRESS (Optional) Set the debug address. Default value is localhost:8000
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
@REM
|
@REM
|
||||||
@REM Environment Variable Prerequisites
|
@REM Environment Variable Prerequisites
|
||||||
@REM
|
@REM
|
||||||
@REM JAVA_HOME Must point at your Java Development Kit installation.
|
@REM JAVA_HOME (Optional) Points to a Java installation.
|
||||||
@REM MAVEN_BATCH_ECHO (Optional) Set to 'on' to enable the echoing of the batch commands.
|
@REM MAVEN_BATCH_ECHO (Optional) Set to 'on' to enable the echoing of the batch commands.
|
||||||
@REM MAVEN_BATCH_PAUSE (Optional) set to 'on' to wait for a key stroke before ending.
|
@REM MAVEN_BATCH_PAUSE (Optional) set to 'on' to wait for a key stroke before ending.
|
||||||
@REM MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
|
@REM MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
|
||||||
|
@ -37,7 +37,7 @@ title %0
|
||||||
|
|
||||||
@setlocal
|
@setlocal
|
||||||
|
|
||||||
IF "%MAVEN_DEBUG_ADDRESS%"=="" @set MAVEN_DEBUG_ADDRESS=localhost:8000
|
if "%MAVEN_DEBUG_ADDRESS%"=="" @set MAVEN_DEBUG_ADDRESS=localhost:8000
|
||||||
|
|
||||||
@set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%MAVEN_DEBUG_ADDRESS%
|
@set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%MAVEN_DEBUG_ADDRESS%
|
||||||
|
|
||||||
|
|
|
@ -16,47 +16,26 @@ if $mingw ; then
|
||||||
JAVA_HOME=`(cd "$JAVA_HOME"; pwd)`
|
JAVA_HOME=`(cd "$JAVA_HOME"; pwd)`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$JAVA_HOME" ]; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
javaExecutable="`which javac`"
|
|
||||||
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
|
|
||||||
# readlink(1) is not available as standard on Solaris 10.
|
|
||||||
readLink=`which readlink`
|
|
||||||
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
|
|
||||||
if $darwin ; then
|
|
||||||
javaHome="`dirname \"$javaExecutable\"`"
|
|
||||||
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
|
|
||||||
else
|
|
||||||
javaExecutable="`readlink -f \"$javaExecutable\"`"
|
|
||||||
fi
|
|
||||||
javaHome="`dirname \"$javaExecutable\"`"
|
|
||||||
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
|
|
||||||
JAVA_HOME="$javaHome"
|
|
||||||
export JAVA_HOME
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$JAVACMD" ] ; then
|
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||||
else
|
else
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
fi
|
|
||||||
else
|
|
||||||
JAVACMD="`which java`"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
echo "The JAVA_HOME environment variable is not defined correctly," >&2
|
echo "The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started." >&2
|
||||||
echo "this environment variable is needed to run this program." >&2
|
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" does not exist." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD="`which java`"
|
||||||
|
|
||||||
if [ -z "$JAVA_HOME" ] ; then
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
echo "Warning: JAVA_HOME environment variable is not set." >&2
|
echo "The java(1) command does not exist in PATH nor is JAVA_HOME set, so Apache Maven cannot be started." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# traverses directory structure from process work directory to filesystem root
|
# traverses directory structure from process work directory to filesystem root
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#
|
#
|
||||||
# Environment Variable Prerequisites
|
# Environment Variable Prerequisites
|
||||||
#
|
#
|
||||||
# JAVA_HOME Must point at your Java Development Kit installation.
|
# JAVA_HOME (Optional) Points to a Java installation.
|
||||||
# MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
|
# MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
|
||||||
# MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
|
# MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
@ -46,26 +46,9 @@ fi
|
||||||
# OS specific support. $var _must_ be set to either true or false.
|
# OS specific support. $var _must_ be set to either true or false.
|
||||||
cygwin=false;
|
cygwin=false;
|
||||||
mingw=false;
|
mingw=false;
|
||||||
darwin=false;
|
|
||||||
case "`uname`" in
|
case "`uname`" in
|
||||||
CYGWIN*) cygwin=true;;
|
CYGWIN*) cygwin=true;;
|
||||||
MINGW*) mingw=true;;
|
MINGW*) mingw=true;;
|
||||||
Darwin*) darwin=true
|
|
||||||
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
|
|
||||||
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
|
|
||||||
if [ -z "$JAVA_HOME" ]; then
|
|
||||||
if [ -x "/usr/libexec/java_home" ]; then
|
|
||||||
export JAVA_HOME="`/usr/libexec/java_home`"
|
|
||||||
else
|
|
||||||
export JAVA_HOME="/Library/Java/Home"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ -z "$JAVA_HOME" ] ; then
|
|
||||||
if [ -r /etc/gentoo-release ] ; then
|
|
||||||
JAVA_HOME=`java-config --jre-home`
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
@REM
|
@REM
|
||||||
@REM Environment Variable Prerequisites
|
@REM Environment Variable Prerequisites
|
||||||
@REM
|
@REM
|
||||||
@REM JAVA_HOME Must point at your Java Development Kit installation.
|
@REM JAVA_HOME (Optional) Points to a Java installation.
|
||||||
@REM MAVEN_BATCH_ECHO (Optional) Set to 'on' to enable the echoing of the batch commands.
|
@REM MAVEN_BATCH_ECHO (Optional) Set to 'on' to enable the echoing of the batch commands.
|
||||||
@REM MAVEN_BATCH_PAUSE (Optional) set to 'on' to wait for a key stroke before ending.
|
@REM MAVEN_BATCH_PAUSE (Optional) set to 'on' to wait for a key stroke before ending.
|
||||||
@REM MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
|
@REM MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
|
||||||
|
@ -46,20 +46,21 @@ if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
|
||||||
set ERROR_CODE=0
|
set ERROR_CODE=0
|
||||||
|
|
||||||
@REM ==== START VALIDATION ====
|
@REM ==== START VALIDATION ====
|
||||||
if not "%JAVA_HOME%"=="" goto OkJHome
|
if not "%JAVA_HOME%"=="" goto javaHomeSet
|
||||||
for %%i in (java.exe) do set "JAVACMD=%%~$PATH:i"
|
for %%i in (java.exe) do set "JAVACMD=%%~$PATH:i"
|
||||||
goto checkJCmd
|
goto checkJavaCmd
|
||||||
|
|
||||||
:OkJHome
|
:javaHomeSet
|
||||||
set "JAVACMD=%JAVA_HOME%\bin\java.exe"
|
set "JAVACMD=%JAVA_HOME%\bin\java.exe"
|
||||||
|
|
||||||
:checkJCmd
|
|
||||||
if not exist "%JAVACMD%" (
|
if not exist "%JAVACMD%" (
|
||||||
echo The JAVA_HOME environment variable is not defined correctly, >&2
|
echo The JAVA_HOME environment variable is not defined correctly, so Apache Maven cannot be started. >&2
|
||||||
echo this environment variable is needed to run this program. >&2
|
echo JAVA_HOME is set to "%JAVA_HOME%", but "%%JAVA_HOME%%\bin\java.exe" does not exist. >&2
|
||||||
goto error
|
goto error
|
||||||
)
|
)
|
||||||
|
|
||||||
if "%JAVA_HOME%"=="" (
|
:checkJavaCmd
|
||||||
echo Warning: JAVA_HOME environment variable is not set. >&2
|
if not exist "%JAVACMD%" (
|
||||||
|
echo The java.exe command does not exist in PATH nor is JAVA_HOME set, so Apache Maven cannot be started. >&2
|
||||||
|
goto error
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue