Archive: Check JRE and install if not there


Check JRE and install if not there
I have been looking at some similar examples, but a bit unsure on why mine is not working

It compiles ok, but running it on a VM with no Java/Apache Tomcat on = just finishes without installing anything.

What am I missing?


;Header Files
!include "MUI2.nsh"

;Definitions
!define PRODUCT_NAME "Dekho"
!define PRODUCT_VERSION "3.2.1"
!define PRODUCT_PUBLISHER "Esri Australia"
!define PRODUCT_WEB_SITE "http://www.dekho.com.au"
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Working\contrib\images\DekhoIcon.ico"



;Basic Settings
Name ${PRODUCT_NAME}
Caption "NSIS ${PRODUCT_VERSION} Setup"
BrandingText "Extending your reach with Dekho"
OutFile "DekhoSetup_v322.exe"

;Default installation folder
InstallDir "$LOCALAPPDATA\Modern UI Test"

;Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Working\license\License.txt"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

;Languages
!insertmacro MUI_LANGUAGE "English"

;Installer Sections



Section "JRE" SEC01
Call DetectJRE
SectionEnd

Section "Tomcat 7" SEC02
File "contrib\apache-tomcat-7.0.21.exe"
ExecWait "$INSTDIR\apache-tomcat-7.0.21.exe"

SectionEnd

Section "Dekho WAR" SEC03
File "contrib\321for10\DASM.war"
CopyFiles `$INSTDIR\DASM.war` `c:\DASM.war`
StrCpy $0 "$INSTDIR\DASM.war" ;Path of copy file from
StrCpy $1 "c:\DASM.war" ;Path of copy file to
StrCpy $2 1 ; only 0 or 1, set 0 to overwrite file if it already exists
System::Call 'kernel32::CopyFile(t r0, t r1, b r2) l'
Pop $0 ; pops a bool. if overwrite is off and there is a file then error will be 1
SectionEnd

;Functions
Function DetectJRE
StrCpy $1 "SOFTWARE\JavaSoft\Java Runtime Environment"
StrCpy $2 0
ReadRegStr $2 HKLM "$1" "CurrentVersion"
StrCmp $2 "" DetectTry2
ReadRegStr $5 HKLM "$1\$2" "JavaHome"
StrCmp $5 "" DetectTry2
goto done

DetectTry2:
ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
StrCmp $2 "" NoJava
ReadRegStr $5 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$2" "JavaHome"
StrCmp $5 "" NoJava done

done:
;All done.
MessageBox MB_OK "$2 JRE installed"

NoJava:
;Write the script to install Java here
File "contrib\jre-6u26-windows-x64.exe"
DetailPrint "Starting the JRE installation"
ExecWait "$TEMP\jre-6u26-windows-x64.exe"
FunctionEnd

You never set INSTDIR. Where is it supposed to put your files?


Technically, he did. Note the InstallDir "$LOCALAPPDATA\Modern UI Test". But yeah, if you want to execwait something in $TEMP, you should first SetOutPath $TEMP before you File Yourfile.ext.

Also, you should probably use $PLUGINSDIR instead of $TEMP.


Thanks guys. (This is my first NSIS tool, but enjoying the learning curve)

If my workflow is :
- check JRE exisits, if not run JRE Installer
- check tomcat exists, if not run Tomcat installer
- throw WAR files under the Tomcat directory

Im a little confused on where I should set my INSTDIR?
Sounds like I shouldnt and I should use either $TEMP or from what I have just read, better still to use $PLUGINSDIR?

Thanks again


InstallDir sets the variable INSTDIR but does not create the directory. The FILE command extracts to $OUTDIR. SetOutPath will set $OUTDIR and will create the output directory if it does not exist. Your test program has no value in $OUTDIR, and doesn't seem to be extracting the files anywhere.

Im a little confused on where I should set my INSTDIR?
Since you want to extract the JRE and Tomcat installers, I'd suggest setting INSTDIR to $PLUGINSDIR. Then when your installer finishes, the JRE and Tomcat installers will be deleted.
SetOutPath $PLUGINSDIR
File "contrib\jre-6u26-windows-x64.exe"
DetailPrint "Starting the JRE installation"
ExecWait "$PLUGINSDIR\jre-6u26-windows-x64.exe"
I also strongly suggest using LogicLib.nsh It makes writing/reading the conditional tests much easier. The 'done' block in function DetectJRE will drop into the 'NoJava' block currently.

THanks, ill tinker with code this weekend and do some reading on LogicLib.nsh


Also note that you should use

ExecWait '"$PLUGINSDIR\jre-6u26-windows-x64.exe"'


rather than
ExecWait "$PLUGINSDIR\jre-6u26-windows-x64.exe"

A good example
18 months late to the party, but this thread comes up if you google for "nsis install tomcat", so I thought I would share this nice example I found...

https://github.com/mathiaslin/openmr...ller_setup.nsh