OpenJDK自动安装脚本 InstallOpenJDK.vbs

Posted windfic

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenJDK自动安装脚本 InstallOpenJDK.vbs相关的知识,希望对你有一定的参考价值。

Oracle JDK 要收费了,Open JDK没有安装包,只有Zip,写了个安装脚本 InstallOpenJDK.vbs

 

技术图片

 

 1 Rem *********************************
 2 Rem **File: InstallOpenJDK.vbs 
 3 Rem **Author: windfic
 4 Rem **Date: 2019-06-05
 5 Rem **Description: 自动安装OpenJDK
 6 Rem *********************************
 7 
 8 
 9 Rem ==把指定目录加入注册表==
10 sub PathToRegPath(Path, Reg) 
11     Set oWshShell = WScript.CreateObject("WScript.Shell")
12     
13     OldPath = oWshShell.RegRead(Reg)
14     
15     if InStr(OldPath, Path)  <= 0 then
16         NewPath = OldPath & ";" & Path
17         oWshShell.RegWrite Reg, NewPath
18     end if
19 end sub
20 
21 Rem ==把指定目录加入系统Path==
22 sub PathToSystemPath(Path) 
23     PathToRegPath Path, "HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\Session Manager\\Environment\\Path"
24 end sub
25 
26 Rem ==安装JDK==
27 sub InstallJDK(Path) 
28     Set oWshShell = WScript.CreateObject("WScript.Shell")
29     Set oFs=WScript.CreateObject("Scripting.FileSystemObject")
30     
31     if oFs.FolderExists(Path) then
32         Home = oFs.GetAbsolutePathName(Path)
33     else
34         Set oFolder = oFs.GetFile(Wscript.ScriptFullName).ParentFolder
35         Home = oFolder.Path & "\\" & Path
36     end if
37     
38     if oFs.FolderExists(Home) then
39         Rem 设置JAVA_HOME
40         oWshShell.RegWrite "HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\Session Manager\\Environment\\JAVA_HOME", Home
41             
42         Rem 把bin加入系统目录
43         PathToSystemPath "%JAVA_HOME%\\bin"
44     else
45         MsgBox("目录:" & Path & " 不存在。")
46     end if
47     
48 end sub 
49 
50 Rem ==安装JRE==
51 sub InstallJRE(Path) 
52     Set oWshShell = WScript.CreateObject("WScript.Shell")
53     Set oFs=WScript.CreateObject("Scripting.FileSystemObject")
54     
55     if oFs.FolderExists(Path) then
56         Home = oFs.GetAbsolutePathName(Path)
57     else
58         Set oFolder = oFs.GetFile(Wscript.ScriptFullName).ParentFolder
59         Home = oFolder.Path & "\\" & Path
60     end if
61     
62     if oFs.FolderExists(Home) then
63         Rem 生成jre目录
64         oWshShell.CurrentDirectory = Home
65         CommandLine = "bin\\jlink.exe --module-path jmods --add-modules java.desktop --output jre"
66         oWshShell.Exec(CommandLine)
67         
68         Rem 设置JRE_HOEM
69         Home = Home & "\\jre"
70         oWshShell.RegWrite "HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\Session Manager\\Environment\\JRE_HOEM", Home
71         
72         Rem 设置CLASSPATH
73         CLASSPATH = ".;%JAVA_HOME%\\lib;%JAVA_HOME%\\jre\\lib"
74         oWshShell.RegWrite "HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\Session Manager\\Environment\\CLASSPATH", CLASSPATH
75         
76         Rem 把jre\\bin加入系统目录
77         PathToSystemPath "%JAVA_HOME%\\jre\\bin"
78     end if
79     
80 end sub 
81 
82 
83 Rem ========================主程序================================
84 
85 JavaHome = "D:\\java\\jdk-12"
86 
87 InstallJDK JavaHome
88 InstallJRE JavaHome
89 
90 MsgBox("执行完成。")

 注:环境变量设置方法来自网络

(完)

 

以上是关于OpenJDK自动安装脚本 InstallOpenJDK.vbs的主要内容,如果未能解决你的问题,请参考以下文章

深入浅出-JVM:编译 jdk

openjdk镜像的tag说明

tomcat的shell安装脚本

redhat 下安装jdk的shell脚本

Mac - 如何在Mac上安装多个版本openjdk并有效管理

OpenJDK-study-002 从GitHub下载openjdk,以及Cygwin的安装