2

我喜欢确定哪些 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.
4

1 回答 1

6

换行

%%k\bin\java.exe --version

"%%k\bin\java.exe" -version

它对我有用。

于 2012-08-21T18:07:29.543 回答