我想确定哪些Java运行时环境可用并检查它们的版本。我的代码将输出正确的jre路径,但无法执行java.exe。
当程序路径是变量时,使用批处理脚本中的参数调用程序的正确方法是什么?
我的剧本
@echo off
:findjres
for /d %%i in ("C:\Program Files\Java\jre*") do (
set /a cpath+=1
call :pushpath "%%i"
)
for /d %%i in ("C:\Program Files (x86)\Java\jre*") do (
set /a cpath+=1
call :pushpath "%%i"
)
goto :versjres
:pushpath
set tpath=%1
set xpath!%cpath%=%tpath:~1,-1%
goto :end
:versjres
for /f "usebackq delims==! tokens=1-3" %%i IN (`set xpath`) do (
echo Array field number %%j have value %%k
%%k\bin\java.exe --version
)
pause
:end
错误
Exception in thread "main" java.lang.NoClassDefFoundError: Files
Caused by: java.lang.ClassNotFoundException: Files
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: Files. Program will exit.
答案 0 :(得分:6)
更改行
%%k\bin\java.exe --version
到
"%%k\bin\java.exe" -version
它对我有用。