- '=================================================================================
- ' 名称:Tomcat5.5.20 + jdk1.5.0_06 + struts1.2 系统环境变量设置程序
- ' 功能:本程序自动设置 TOMCAT_HOME, CATALINA_HOME, JAVA_HOME, CLASSPATH, PATH等环
- ' 境变量如果您以前已经设置过相关环境变量,本程序将覆盖相关设置,如果用到了
- ' Struts,将将相关文件复制到 %TOMCAT_HOME%\Common\lib 下面。
- ' 作者:HLDGAOFENG
- ' 日期:2008-09-17
- '=================================================================================
-
-
- ' 修改这两个常量为你自己的路径,如果为空,将在运行时提示你选择路径。
- ' --------------------------------------------------------------------------------
- ' TOMCAT HOME
- Const TOMCAT_HOME = ""
-
- ' JDK HOME
- Const JAVA_HOME = ""
- ' --------------------------------------------------------------------------------
-
-
- ' 定义相关变量
- Dim sTomcatHome
- Dim sJavaHome
- Dim sClassPath
- Dim sPath
-
- ' 创建 Shell 对象,以便操作系统环境变量
- Dim wsh, envSystem, shell, selFolder, selFolderItem
- Set wsh = WScript.CreateObject("WScript.Shell")
- Set envSystem = wsh.Environment("system")
- Set shell = CreateObject("Shell.Application")
-
- ' 如果没有指定 TOMCAT_HOME 则弹出浏览目录窗口让用户选择一个
- If TOMCAT_HOME = "" Then
- Set selFolder = shell.BrowseForFolder(0, "请选择 TOMCAT_HOME 目录:" & _
- vbCrLf & "如:C:\apache-tomcat-5.5.20", 0, ssfDRIVES)
- If selFolder Is Nothing Then WScript.Quit
- Set selFolderItem = selFolder.Self
- sTomcatHome = selFolderItem.Path
- Else
- sTomcatHome = TOMCAT_HOME
- End If
-
- ' 如果没有指定 JAVA_HOME 则弹出浏览目录窗口让用户选择一个
- If JAVA_HOME = "" Then
- Set selFolder = shell.BrowseForFolder(0, "请选择 JAVA_HOME 目录:" & _
- vbCrLf & "如:C:\Program Files\Java\jdk1.5.0_06", 0, ssfDRIVES)
- If selFolder Is Nothing Then WScript.Quit
- Set selFolderItem = selFolder.Self
- sJavaHome = selFolderItem.Path
- Else
- sJavaHome = JAVA_HOME
- End If
-
- ' CLASS_PATH 一般配置。(*)我不太清楚要用到struts的其它包,如果用到,自己将相关包加到里面吧。
- ' .;d:\struts\commons-logging.jar;d:\struts\antlr.jar;d:\struts\jakarta-oro.jar;d:\struts\commons-digester.jar;D:\struts\commons-validator.jar;D:\struts\struts.jar;D:\struts\commons-beanutils.jar
- sClassPath = ".;" & _
- "%JAVA_HOME%\lib\tools.jar;" & _
- "%JAVA_HOME%\lib\dt.jar;" & _
- "%JAVA_HOME%\lib\mysql-connector-java-3.0.14-production-bin.jar;" & _
- "%CATALINA_HOME%\common\lib\servlet-api.jar;" & _
- "%CATALINA_HOME%\common\lib\struts.jar;"
-
- ' 得到原来的 path 系统环境变量,再加上 %CATALINA_HOME%\common\lib;%JAVA_HOME%\bin;
- sPath = envSystem("PATH")
- If InStr(1, LCase(sPath), "%catalina_home%\common\lib") < 1 Then
- sPath = "%CATALINA_HOME%\common\lib;" & sPath
- End If
- If InStr(1, LCase(sPath), "%java_home%\bin") < 1 Then
- sPath = "%JAVA_HOME%\bin;" & sPath
- End If
-
- ' 再次请用户确认之后再进行修改
- If MsgBox("正准备将您的 JAVA_HOME 系统环境变量设置为:" & vbCrlf & _
- sJavaHome & vbCrlf & vbCrlf & _
- "正准备将您的 CATALINA_HOME,TOMCAT_HOME 系统环境变量设置为:" & vbCrlf & _
- sTomcatHome & vbCrlf & vbCrlf & _
- "正准备将您的 CLASSPATH 系统环境变量设置为:" & vbCrlf & _
- sClassPath & vbCrlf & vbCrlf & _
- "正准备将您的 PATH 系统环境变量设置为:" & vbCrlf & _
- sPath & vbCrlf & vbCrlf & _
- "您确定要继续吗?", vbYesNo + vbQuestion + vbDefaultButton2, "收集信息完成,正准备设置环境变量……") <> vbYes Then
- WScript.Quit
- End If
-
-
- ' 设置系统环境变量
- envSystem("TOMCAT_HOME") = sTomcatHome
- envSystem("CATALINA_HOME") = sTomcatHome
- envSystem("JAVA_HOME") = sJavaHome
- envSystem("CLASSPATH") = sClassPath
- envSystem("PATH") = sPath
-
- MsgBox "环境变量已经设置成功!", vbinformation
-
- set wsh = nothing
复制代码
http://dongbian.blog.51cto.com/2694115/701486 |