Archive: Copying files to the JRE install directory on windows


Copying files to the JRE install directory on windows
Morning!

I have been working on an installer for a java application that a friend of mine wrote which requires some extra files to be copied into the current java install folder (the application makes use of the serial port which requires extra libraries to be installed).

More specifically i would like my application to be installed to C:/program files/my app/application.jar (no problem) and then the extra library files to be copied to

..\JavaInstallDirectory/MostCurrentVersion/lib/comm.java
..\JavaInstallDirectory/MostCurrentVersion/lib/comm.properties.java
..\JavaInstallDirectory/MostCurrentVersion/bin/wincom32.dll

on my machine the folder is
C:\Program Files\Java\jre1.6.0_07

but i know it will differ from machine to machine and user to user.

I did some reading around and found the Slightly Better Java Launcher script on the NSIS wiki (and its variants) and have been trying to use it get the current java install directory and then copy in the files that I want.

The script complies ok but the function call doesn't seem to be working properly or my variable declarations are not right (I inserted a line to show the "found" java path in a msgbox but it comes up blank.

Alas my inexperience of using NSIS has lead me to failure.
The script file is attached; if I could have a little guidance as to where I am going wrong then I would be most appreciative.


Many thanks
A


Your error is in the label JreFound. Up until then everything is correct and works fine. However you echange $R0 with the top of the stack which is empty. Hence the empty string. I'm not even sure what you are trying to do there. But before that label $R0 is exactly what you want it to be. Read up more on push/pop/exch

This works


Function GetJRE
;
; Find JRE (javaw.exe)
; 1 - in .\jre directory (JRE Installed with application)
; 2 - in JAVA_HOME environment variable
; 3 - in the registry
; 4 - assume javaw.exe in current dir or PATH

;Push $R0
;Push $R1

ClearErrors
StrCpy $R0 "$INSTDIR\jre\bin\javaw.exe"
IfFileExists $R0 JreFound
StrCpy $R0 ""

ClearErrors
ReadEnvStr $R0 "JAVA_HOME"
StrCpy $R0 "$R0\bin\javaw.exe"
IfErrors 0 JreFound

ClearErrors
ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
MessageBox MB_OK $R1
ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
StrCpy $R0 "$R0\bin\javaw.exe"

IfErrors 0 JreFound
StrCpy $R0 "javaw.exe"

JreFound:
;Pop $R1
;Exch $R0
Push $R0
messageBox MB_OK "$R0"
FunctionEnd


When GetJRE returns and you pop $R0 you get what you expect

Ah i think I see what has gone wrong here - i'm a design engineer by trade so this programming lark is not in my comfort zone. Thanks for the tip - i found the push pop tutorial on the wiki; i'll give it a proper going over.

Thanks again
A