Java Launcher: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library)
 
m (Updated author and download links, and changed format of some pages.)
Line 77: Line 77:
</highlight-nsis>
</highlight-nsis>


 
Page author: [[User:Baz|Baz]]
Page author: Baz

Revision as of 12:37, 23 April 2005

Description

Here is a NSIS script which can be used to launch Java programs the easy way.

It will search for the JRE the following way:

 1 - in jre directory (if you have JRE Installed with your application)
 2 - in JAVA_HOME environment variable
 3 - in the registry
 4 - assume java.exe in current dir or PATH

In this example NSIS is not used as an installer but as a windows program.

There's no programming language out there in which it can be done this simple!

Have fun! (can you believe people want you to pay for this!)

The Script

; Java Launcher
;--------------
 
Name "Java Launcher"
Caption "Java Launcher"
Icon "Java Launcher.ico"
OutFile "Java Launcher.exe"
 
SilentInstall silent
AutoCloseWindow true
ShowInstDetails nevershow
 
!define CLASSPATH ".;lib;lib\myJar"
!define CLASS "org.me.myProgram"
 
Section ""
  Call GetJRE
  Pop $R0
 
  ; change for your purpose (-jar etc.)
  StrCpy $0 '"$R0" -classpath "${CLASSPATH}" ${CLASS}'
 
  SetOutPath $EXEDIR
  Exec $0
SectionEnd
 
Function GetJRE
;
;  Find JRE (Java.exe)
;  1 - in .\jre directory (JRE Installed with application)
;  2 - in JAVA_HOME environment variable
;  3 - in the registry
;  4 - assume java.exe in current dir or PATH
 
  Push $R0
  Push $R1
 
  ClearErrors
  StrCpy $R0 "$EXEDIR\jre\bin\java.exe"
  IfFileExists $R0 JreFound
  StrCpy $R0 ""
 
  ClearErrors
  ReadEnvStr $R0 "JAVA_HOME"
  StrCpy $R0 "$R0\bin\java.exe"
  IfErrors 0 JreFound
 
  ClearErrors
  ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
  ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
  StrCpy $R0 "$R0\bin\java.exe"
 
  IfErrors 0 JreFound
  StrCpy $R0 "java.exe"
 
 JreFound:
  Pop $R1
  Exch $R0
FunctionEnd

Page author: Baz