Skip to content

Instantly share code, notes, and snippets.

@corpix
Created August 16, 2012 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corpix/3373352 to your computer and use it in GitHub Desktop.
Save corpix/3373352 to your computer and use it in GitHub Desktop.
NSIS Java app launcher
; Java Launcher
;--------------
Name "Batch playlist"
Caption "Batch playlist"
Icon "playlist-icon.ico"
OutFile "BatchPlaylist.exe"
SilentInstall silent
AutoCloseWindow true
ShowInstDetails nevershow
RequestExecutionLevel user ; This is not an installer, there is no need in administrator privilege(thats true by default)
!define JNA_LIBRARY_PATH ".\modules\lib"
Section ""
Call GetJRE
Pop $R0
; change for your purpose (-jar etc.)
StrCpy $0 '"$R0" -jar -Djna.library.path="${JNA_LIBRARY_PATH}" "dist\batch-playlist.jar"'
SetOutPath $EXEDIR
Exec $0
SectionEnd
Function GetJRE
;
; returns the full path of a valid java.exe
; looks in:
; 1 - .\jre directory (JRE Installed with application)
; 2 - JAVA_HOME environment variable
; 3 - the registry
; 4 - hopes it is in current dir or PATH
Push $R0
Push $R1
; use javaw.exe to avoid dosbox.
; use java.exe to keep stdout/stderr
!define JAVAEXE "javaw.exe"
ClearErrors
StrCpy $R0 "$EXEDIR\jre\bin\${JAVAEXE}"
IfFileExists $R0 JreFound ;; 1) found it locally
StrCpy $R0 ""
ClearErrors
ReadEnvStr $R0 "JAVA_HOME"
StrCpy $R0 "$R0\bin\${JAVAEXE}"
IfErrors 0 JreFound ;; 2) found it in JAVA_HOME
ClearErrors
ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
StrCpy $R0 "$R0\bin\${JAVAEXE}"
IfErrors 0 JreFound ;; 3) found it in the registry
StrCpy $R0 "${JAVAEXE}" ;; 4) wishing you good luck
JreFound:
Pop $R1
Exch $R0
FunctionEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment