Hi,

I have been studying alternatives for making the Geoserver startup.bat to find 
the location of jre from Windows 7 machine automatically. Currently the 
startup.bat checks only if the JAVA_HOME environment variable is set and if it 
is not then the script stops and asks user to set it. I believe that a long 
time ago the idea has been that one Java version on a computer is enough and 
the latest one is the best and everybody could be made happy by launching all 
programs from %JAVA_HOME%\bin\java.exe.

Now I can see from my two year old computer that Java is extremely wide spread 
- I found totally 28 copies of java.exe from it!  Amazingly many programs seem 
to install with its own copy of jre. No wonder that our admins do not set 
JAVA_HOME at all for our computers. After a short web review I believe this is 
status quo nowadays and startup.bat can't rely on finding the JAVA_HOME 
variable.

Literature review
==============

1) There seems to be a modern alternative for JAVA_HOME which is using Windows 
registry with key HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java. 
http://stackoverflow.com/questions/3930383/jre-installation-directory-in-windows
However, at least on our computers those keys are not set.  Conclusion: Not 
reliable.

2) If Java is installed with installer then the Windows start menu has a few 
Java control tools. Especially the information that is shown by the javacpl.exe 
tool is stored into file: 
C:\Users\[user_name]\AppData\LocalLow\Sun\Java\Deployment. The file contains 
rows like
deployment.javaws.jre.0.path=C\:\\Program Files 
(x86)\\Java\\jre7\\bin\\javaw.exe
deployment.javaws.jre.0.product=1.7.0_51

3) Usually one copy of java.exe and javaw.exe can be found either from 
\Windows\System32 directory or in case of 32-bit jre on 64-bit Windows, from 
\Windows\SysWOW64. Those executables seem to start the highest and latest jre 
version of all versions which are listed by javacpl.exe.
 
4) Jre can also be installed simply by copying the program files to some 
directory. In this case jre can't be found by checking the registry or 
AppData\LocalLow\Sun\Java\Deployment file. Sometimes this jre path is added 
into PATH variable but fortunately not so often nowadays.

Now how should we fix the startup.bat file? What about making it to use this 
logic:

1) If JAVA_HOME is set as system or user variable it is probably done for 
reason so use it.
2) Check if there is java.exe in \System32. That would start 64-bit jre on 
64-bit computers and 32-bit jre on 32-bit computers.
3) If 2) fails and computer is 64-bit version, try to find 32-bit jre with the 
SysWOW64 system.
4) If all previous fail, prompt user to edit startup.bat file and set JAVA_HOME 
there.

-Jukka Rahkonen-



------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Geoserver-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

Reply via email to