'''''''''''''''''''''''''''''''''''''''
'This qtp script is used for setting the java environment variable automaticly.
'save the scirpt under the JDK folder
'author : yks(YangKongSuo)
'if forward this script please indicate the author
''''''''''''''''''''''''''''''''''''''''
Dim fso,wsh,env_path,classpath,TestDir
Set fso = CreateObject("Scripting.FileSystemObject")
TestDir = Environment("TestDir")
J2SDK_path = fso.GetParentFolderName(TestDir)
Set wsh = CreateObject("WScript.Shell")
If not fso.FileExists(J2SDK_path&"\bin\java.exe") then
msgbox (J2SDK_path&"\bin\java.exe not existing")
ExitTest
else
wsh.Environment("system").Item("JAVA_HOME")=J2SDK_path
env_path = wsh.Environment("system").Item("PATH")
If instr(1,env_path, ";" & J2SDK_path & "\bin",1) = 0 Then
wsh.Environment("system").Item("PATH")=env_path & ";" & J2SDK_path & "\bin"
End If
classpath = wsh.Environment("system").Item("CLASSPATH")
If instr(1,classpath, ".;"&J2SDK_path&"\lib\tools.jar",1) = 0 Then
wsh.Environment("system").Item("CLASSPATH")=classpath & ".;"&J2SDK_path&"\lib\tools.jar"
classpath = wsh.Environment("system").Item("CLASSPATH")
wsh.Environment("system").Item("CLASSPATH")=classpath&";"&J2SDK_path&"\lib\dt.jar"
classpath = wsh.Environment("system").Item("CLASSPATH")
wsh.Environment("system").Item("CLASSPATH")=classpath&";"&J2SDK_path&"\jre\lib\rt.jar"
End If
end if
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/