Archive: JVM detection routine?


JVM detection routine?
Anyone willing to share a jvm detection/prompt routine? I use the one by Tomcat team but that doesn't work in all cases.


up i'm interested!


This is what I use, if there are additional/improved version I'd be highly interested as well...

Function DetectJava
# this function detects Sun Java from registry and calls the JavaFind utility otherwise

# This is the first time we run the JavaFind
StrCpy $5 "No"

StartCheck:
# First get the installed version (if any) in $2
# then get the path in $6

StrCpy $0 "SOFTWARE\JavaSoft\Java Runtime Environment"
# Get JRE installed version
ReadRegStr $2 HKLM $0 "CurrentVersion"
StrCmp $2 "" DetectTry2

# Get JRE path
ReadRegStr $6 HKLM "$0\$2" "JavaHome"
StrCmp $6 "" DetectTry2

#We seem to have a JRE now
Goto GetJRE

DetectTry2:
# we did not get a JRE, but there might be a SDK installed
StrCpy $0 "Software\JavaSoft\Java Development Kit"
# Get JRE installed version
ReadRegStr $2 HKLM $0 "CurrentVersion"
StrCmp $2 "" RunJavaFind

# Get JRE path
ReadRegStr $6 HKLM "$0\$2" "JavaHome"
StrCmp $6 "" RunJavaFind

GetJRE:
StrCpy $3 "$6\bin\java.exe"
StrCpy $4 "$6\bin\javaw.exe"

# Check if files exists and write paths
IfFileExists $3 0 RunJavaFind
WriteINIStr "$INSTDIR\FLaunch.ini" "Freenet Launcher" "JavaExec" $3
IfFileExists $4 0 RunJavaFind
WriteINIStr "$INSTDIR\FLaunch.ini" "Freenet Launcher" "Javaw" $4

# Jump to the end if we did the Java recognition correctly
Goto End

RunJavaFind:

!ifdef embedJava
# Install Java runtime only if not found
DetailPrint "Lauching Sun's Java Runtime Environment installation..."
SetOutPath "$TEMP"
File ${JAVAINSTALLER}
ExecWait "$TEMP\${JAVAINSTALLER}"
Delete "$TEMP\${JAVAINSTALLER}"
Goto StartCheck
!else
# opening download page
MessageBox MB_YESNO "I did not find Sun's Java Runtime Environment which is needed for Freenet.$\r$\nHit 'Yes' to open the download page for Java (http://java.sun.com),$\r$\n'No' to cancel the installation." IDYES GetJava
Abort

GetJava:
# Open the download page for Sun's Java
ExecShell "open" "http://javasoft.com/"
Sleep 5000
MessageBox MB_OKCANCEL "Press OK to continue the Freenet installation AFTER having installed Java,$\r$\nCANCEL to abort the installation." IDOK StartCheck
Abort
!endif

AbortJava:
MessageBox MB_OK|MB_ICONSTOP "I still can't find any Java interpreter. Did you really installed the JRE?$\r$\nInstallation will now stop."
Abort

End:
# Restore $0, $2, $5 and $6
Pop $6
Pop $5
Pop $2
Pop $0
FunctionEnd


Also check %JAVA_HOME%
I got a *lot* of feedback on that subject, and although auto-detecting with the registry is quite nice, many people want to specify the JDK to use using a JAVA_HOME env variable.

Also, many JDKs don't set the normal keys, so it creates lots of problems to rely only on the registry.


need component of some sort
Seems like the best way to do this is to have a screen similar to InstallAnywhere that lists all detected JVMs (from registry) and then gives the option for a more advanced JVM search for "orphaned" JVMs, which are common on developer machines... just the /jre file system with no registry entries.

I'm game for trying to write such a component but I've only last week written my first short NSIS install script so I'd probably need some guidance to get me going. I'm assuming such a component can be written an "plugged in", right?

Anybody interested in helping me give this a shot? NSIS, with such a feature, would have to be the absolute preferred way of all time to install Java apps on Win32.


Sure, plugins are easy to write and there are example plugins in the NSIS/Contrib directory. ExDLL is the directory containing the basic template for a plugin (examples given in Delphi and C code). I'm not that sure how easy it is to show your own window from a plugin but I'm pretty sure it can be done (I think the NSISUpdate program does it).

Thing is I think you could write this without a plugin, just a script that checks for registry entries and maybe scan the disk and then uses an InstallOptions page to show the results.


good idea
Thanks for the input- after some review I think you are probably right- this can probably be done more easily and made equally as reusable with InstallOptions which I will dive into now.

I'm sure I'll be back at some point with some questions.

Thanks


You can save some time if you use LangDLL. LangDLL doesn't really care if you give it a language id or the path to Java. If you don't like the dialog showing as a combobox you can just change the resources and recompile.


Check the nsis archive
http://nsis.sourceforge.net/archive/...nstances=0,110

Chris


after more review...
Okay,

Now that I've gotten into this, I don't think I can accomplish what I wanted with what I have available.

The screen below gives three functions-

1. auto detected JVMs, presumably from the registry and perhaps a java.exe in the system path.

2. user requestable more intesive auto-discovery. This involves browsing the file system for other JVMs. An extra step here is to pull back the version from the JVM when it is found. There may be a way to check a .dll, but if all else failed, one could exec "java.exe -version" and capture the system out.

3. faster, direct discovery. Let the user point you right at a JRE or JDK directory via a file chooser if they know where it is and save themselves the misery of waiting for the entire file system to be scanned. Again, in this case the version needs to be extacted from the JDK they specified.

This seems like more that could be done with the basic script or InstallOptions.

[img]http://b-gallery******shot.jpg[/img]