although this seems to be an old and common problem, I couldn't find any satisfactory answer.
Problem: Validate JRE_HOME
We had JAVA bundled with our application using Advanced Installer, but we decided to rely on an already installed java. We set then a prerequisite so to have the JRE_HOME environmental variable set before the install package is executed. This is due to the fact that apparently Advanced Installer (because of the underlying windows structure) cannot set and use Environmental variables during the same installations, and in the installation package there are custom actions which require a JRE_HOME variable to be present (please correct me if there is an alternative way).
Now the problem is, we want to validate the JRE_HOME folder to be sure that it is pointing to a valid path (i.e. which does not end with "\", which contains a "bin" folder and a "java.exe" file, etc...) for example, if "%JRE_HOME%\bin\java.exe -version" can be executed, there is a valid JRE_HOME.
We tried with a vbscript, which is the following:
Code: Select all
'Do not display errors
On Error Resume Next
Set wshShell = CreateObject( "WScript.Shell" )
'Set JRE_HOME environmental variable in JREHOME variable
Dim JREHOME
JREHOME = wshShell.ExpandEnvironmentStrings( "%JRE_HOME%" )
DIM returnValue
returnValue = -1
'Check if there is a JRE_HOME environmental variable
If JREHOME = "%JRE_HOME%" Then
'JRE_HOME does not exists
'WScript.Echo "JRE_HOME does not exist"
returnValue = 1
End if
'JRE_HOME exists!
'Check if it ends with backslash
If (InStrRev(JREHOME, "\") = Len(JREHOME)) Then
WScript.Echo "JRE_HOME ends with ""\"". This is not allowed. Exiting..."
WScript.Quit(1)
End if
'The path seems to be valid. Trying to execute "java -version"
JAVA = JREHOME & "\bin\java.exe"
returnValue = WSHShell.run (chr(34) & JAVA & chr(34) & " -version" )
If (returnValue = 0) Then
WScript.Echo "JRE_HOME is properly set"
ElseIf (returnValue <> 0) Then
WScript.Echo "Error locating the java binary in the JRE_HOME folder. JRE_HOME is set to: " & JREHOME
End if
WScript.Quit(returnValue)
We tried with a "Search" within Advanced Installer, but without success.
Is it maybe possible to create an additional wizard and run the main installation after the wizard properly set and /or validated the JRE_HOME?
Thanks!
FOLLOW US
Get the latest news in Application Packaging