1 Star 0 Fork 0

神蛐/DbVisualizer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
resolveJRE.bat 4.03 KB
一键复制 编辑 原始数据 按行查看 历史
神蛐 提交于 2020-09-24 17:30 . 新的工具
rem script for locating a valid JRE
rem designed for use by dbviscmd.bat and dbvisgui.bat
rem inspects %JAVA_EXEC%, dbvis installation folder and %PATH% for a JRE and checks that the version is OK
rem returns the executable command (quoted) and the version number on stdout, separated by *
rem
rem NOTE: Modifies environment variables - caller is expected to run with 'setlocal'!
rem
rem Example usage:
rem for /f "delims=* tokens=1-2" %%a in ('reolveJRE.bat') do (
rem set JAVA_EXEC=%%a
rem set JAVA_MAJOR_VERSION=%%b
rem )
rem ----------------------------------------------------------------------------
rem init
rem ----------------------------------------------------------------------------
set DBVIS_HOME=%~dp0
set MIN_VERSION=8
rem check parameters and variables
if NOT "%~1" == "" goto READ_P1
if defined JAVA_EXEC goto READ_ENV
goto FIND_JAVA
rem ----------------------------------------------------------------------------
rem RESOLVE JRE
rem ----------------------------------------------------------------------------
rem resolve which JRE to use
:FIND_JAVA
rem no parameters given, try to locate a JRE
if not defined JAVA_EXEC (
set MY_JAVA=java
set JAVA_EXEC=java
if exist "%DBVIS_HOME%\jre\bin\java.exe" (
cd /d "%DBVIS_HOME%\jre\bin"
set JAVA_EXEC="%DBVIS_HOME%\jre\bin\java.exe"
)
)
goto EXTRACT
:READ_ENV
rem we found a JRE in environment variables
rem we don't know if it's quoted or not, so we do a recursive call with the variable as command line argument
rem (we can strip quotes and handle paths on positional parameters, but not on environment variables)
%0 %JAVA_EXEC%
:READ_P1
rem A JRE was given as parameter to the script.
rem An unquoted path with spaces is interpreted as many parameters, we need to fix this:
rem if parameter 1 is not quoted do a recursive call with all params quoted
if %1==%~1 %0 "%*"
rem OK, we have a single quoted parameter - is it a file?
IF "%~dpnx1" == %1 GOTO READ_P1_FILE
IF "%~pnx1" == %1 GOTO READ_P1_FILE
GOTO READ_P1_COMMAND
:READ_P1_COMMAND
rem Parameter is not a file. Is it an executable command?
where %1 >NUL 2>&1
if errorlevel 1 echo Using environment variable JAVA_EXEC: No such command: [%1] && GOTO ERROR
rem all good:
rem set JAVA_EXEC as the quoted path, cd into the directory and set java as a local command (unquoted)
set JAVA_EXEC=%1
cd /d "%~dp1" >NUL
set MY_JAVA=%~nx1
goto EXTRACT
:READ_P1_FILE
rem Parameter 1 is a file argument. Does it exist?
IF NOT EXIST %1 echo Using environment variable JAVA_EXEC: No such file: [%1] && goto ERROR
rem set JAVA_EXEC as the quoted path, cd into the directory and set java as a local command (unquoted)
set JAVA_EXEC=%1
cd /d "%~dp1" >NUL
set MY_JAVA=%~nx1
goto EXTRACT
rem ----------------------------------------------------------------------------
rem EXTRACT VERSION
rem ----------------------------------------------------------------------------
:EXTRACT
rem Extract the version string
for /f "tokens=3" %%g in ('%MY_JAVA% -version 2^>^&1 ^| findstr /i "version"') do (
set VERSION_STRING=%%g
)
rem Check that version was understood
if defined VERSION_STRING if NOT [%VERSION_STRING%]==[""] goto PARSE
echo Unable to extract java version from [%JAVA_EXEC%]
goto ERROR
:PARSE
rem Remove the double-quotes
set VERSION_STRING=%VERSION_STRING:"=%
rem Extract second number (x) if we are "1.x.y" and first number if not (E.g. 9.0, 10.0)
for /f "delims=. tokens=1-3" %%v in ("%VERSION_STRING%") do (
if /I "%%v" EQU "1" (
set JAVA_MAJOR_VERSION=%%w
) else (
set JAVA_MAJOR_VERSION=%%v
)
)
:CHECK
rem check version
if /I %JAVA_MAJOR_VERSION% LSS %MIN_VERSION% (
echo Java version %VERSION_STRING% is not supported. At least Java %MIN_VERSION% is required.
goto ERROR
)
GOTO OK
rem ----------------------------------------------------------------------------
rem EXIT
rem ----------------------------------------------------------------------------
:ERROR
rem exit with an error level after having echoed the error string on stdout
exit /B 1
:OK
rem exit with an ok error level after having set JAVA_EXEC and JAVA_MAJOR_VERSION variables
exit /B 0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qushen0925/db-visualizer.git
git@gitee.com:qushen0925/db-visualizer.git
qushen0925
db-visualizer
DbVisualizer
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385