Validate JRE_HOME - Advanced Installer Community
daniele
Posts: 1
Joined: Tue Nov 04, 2014 12:21 pm

Validate JRE_HOME

Hello,
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)
but even following the instructions and inserting it as a custom action (vbs file or inline script) it doesn't seem to run (a simple msgbox seems to have a return code = 3).

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!
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Validate JRE_HOME

Hello and welcome to Advanced Installer forums,

Thank you for your interest in Advanced Installer.
but even following the instructions and inserting it as a custom action (vbs file or inline script) it doesn't seem to run (a simple msgbox seems to have a return code = 3).
I'm afraid I don't fully understand what behavior you are encountering. Can you please launch your VBS file using a "Launch attached file" custom action and see if this helps? Also, can you please send us the .AIP/S (poject file/s) and a verbose log of the installation to support at advancedinstaller dot com so we can investigate them?
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?
I'm not sure what you mean by additional wizard, can you exemplify a bit?

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”