本帖最后由 iiido 于 2017-2-13 15:44 编辑
Win7 x86 测试卡死,提供其他方案,取自网络。
A方案:批处理(扩展名bat),批处理文件需放入jdk文件夹里运行,注:设置系统变量,切换用户可用
[Asm] 纯文本查看 复制代码 @echo off
title 设置Java环境变量
@reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v ClassPath /t reg_expand_sz /d "%%JAVA_HOME%%\lib;%%Java_Home%%\lib\dt.jar;%%Java_Home%%\lib\tools.jar" /f
@reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v path /t reg_expand_sz /d "%path%;%%Java_Home%%\bin" /f
@reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Java_Home /t reg_sz /d "%cd%" /f
gpupdate /force
javac
echo 若正确显示帮助信息,则搭建成功。
@pause
B方案:
脚本(扩展名vbs),直接运行,需杀毒软件放行,注:设置用户变量,切换用户不可用.
[Asm] 纯文本查看 复制代码 Set fso = CreateObject("Scripting.FileSystemObject")
Set w = createobject("wscript.shell")
sub error()
msgbox "该目录不是JDK安装目录!",16 + 4096,"设置JDK环境变量"
main()
end sub
'==================自动查找JDK路径(在Program Files文件夹中)==================
function findJava()
dim java_path
windows_disk = fso.getdrivename(fso.getspecialfolder(WindowsFolder))
if fso.folderexists(windows_disk&"\Program Files\Java\") then
set java_path = fso.getfolder("C:\Program Files\Java\")
elseif fso.folderexists(windows_disk&"\Program Files (x86)\Java\") then
set java_path = fso.getfolder("C:\Program Files (x86)\Java\")
end if
For Each folder In java_path.subfolders
If InStr(1, folder, "jdk") > 0 Then
if fso.fileexists(folder&"\bin\java.exe") then
findJava = folder
end if
end if
next
end function
sub main()
folder = findJava()
java = folder
autoSet = true
if folder = "" then
Set objShell = CreateObject("Shell.Application")
Set folder = objShell.BrowseForFolder(0,"选择JDK的安装目录:"&chr(13)&"设置环境变量需要一些时间,请耐心等待",0,17)
if folder is nothing then
wscript.quit
end if
if folder.self.path = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" then
error()
end if
set java = fso.getfolder(folder.self.path)
autoSet = false
end if
if fso.fileexists(java&"\bin\java.exe") then
java_home = w.Environment("user").Item("java_home")
if java_home <> "" then
msgbox "已经不需要再设置了!",48 + 4096,"设置JDK环境变量"
else
if autoSet then
msgbox "已找到JDK目录"&chr(13)&"将在点击确定后进行设置,可能需要一些时间",64,"设置JDK环境变量"
end if
w.Environment("user").Item("java_home") = java
w.Environment("user").Item("Path") = w.Environment("user").Item("Path")&"%java_home%\bin"
w.Environment("user").Item("classpath") = w.Environment("user").Item("classpath")&";.;%java_home%\lib\tools.jar;%java_home%\lib\dt.jar"
msgbox "环境变量设置完毕!",64 + 4096,"设置JDK环境变量"
end if
else
error()
end if
end sub
main()
|