Changeset 2362862


Ignore:
Timestamp:
Nov 9, 2012 11:53:02 PM (8 years ago)
Author:
kytv <kytv@…>
Branches:
master
Children:
f8133b7
Parents:
f287ed4
Message:

eepget: If java binary is not found, try to determine where java.exe is located.

In my testing:
32 bit Windows (and, of course, 32 bit JRE) = Java added to the PATH
64 bit Windows and 64 bit JRE = Java added to the PATH
64 bit Windows and 32 bit JRE = Java *not* added to the PATH.

So…with this check-in:

  • If the environment variable JAVA is set in the script, we'll use that manually specified Java. We will not look in the registry, but we'll check to make sure that the binary exists.
  • If Java is found in the system path, we'll use it instead. We will not look in the registry.
  • If the variable is not set manually and Java is not in the system path we'll look in the registry to find the java binary.

I've tested this in Windows XP, Vista, and 7 but it should work in any supported version
of Windows.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • history.txt

    rf287ed4 r2362862  
     12012-11-10 kytv
     2* eepget: Add logic to figure out the path to java.exe (java isn't always added to the system path
     3  in Windows) (ticket #769)
     4
    152012-11-05 zzz
    26 * Console:
  • installer/resources/eepget.bat

    rf287ed4 r2362862  
    11@echo off
     2
     3::
     4:: This should have been changed by the installer
     5::
    26set _I2PHOME=%INSTALL_PATH
    3 java -cp "%_I2PHOME%\lib\i2p.jar" net.i2p.util.EepGet %1 %2 %3 %4 %5
     7
     8:: In case the autodetection fails or a specific Java binary is needed,
     9:: uncomment the next line and set the full path to "java.exe"
     10::
     11REM set JAVA=
     12
     13::
     14:: If we find Java in the path, or a specific Java binary was set, let's use
     15:: it instead of figuring it out ourselves.
     16::
     17if defined JAVA (
     18    goto eepget
     19) else (
     20    for %%I in (java.exe) do set JAVA=%%~$PATH:I
     21)
     22::
     23:: Does "elif" exist in Windows? It doesn't seem to...
     24::
     25if defined JAVA GOTO eepget
     26
     27::
     28:: We should only end up here if Java isn't in the path
     29::
     30setlocal ENABLEEXTENSIONS
     31set KEY1="HKLM\SOFTWARE\JavaSoft\Java Runtime Environment"
     32set KEY2="HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment"
     33set VALUE_NAME=CurrentVersion
     34
     35::
     36:: The key specified in the KEY1 variable should exist on 32bit windows
     37:: and 64bit Windows with a 64bit JRE.
     38::
     39:: The key specified in KEY2 will be used on a 64bit Windows with a 32-bit JRE.
     40::
     41reg query %KEY1% 2>nul && set KEY_NAME=%KEY1% || set KEY_NAME=%KEY2%
     42
     43::
     44:: Get the current version from the registry
     45::
     46FOR /F "tokens=2,*" %%A IN ('REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul') DO (
     47    set VersionValue=%%B
     48)
     49
     50::
     51:: Since we didn't find the registry keys (and JAVA wasn't set in this script),
     52:: we'll quit.
     53::
     54if not defined VersionValue (
     55    @echo Unable to find %KEY_NAME%\%VALUE_NAME% in the registry.
     56    @echo Please edit this script and manually set the variable JAVA.
     57    goto end
     58)
     59
     60set JAVA_CURRENT=%KEY_NAME%\%VersionValue%
     61set J_HOME=JavaHome
     62
     63::
     64:: Get the Java Home
     65::
     66FOR /F "tokens=2,*" %%A IN ('REG QUERY %JAVA_CURRENT% /v %J_HOME% 2^>nul') DO (
     67    set JAVA_PATH=%%B
     68)
     69
     70if not defined JAVA (set JAVA="%JAVA_PATH%\bin\java.exe")
     71
     72:eepget
     73::
     74:: The binary in %JAVA% should exist, assuming it was set by us. Perhaps it
     75:: won't if the user specified it manually. Let's check to be sure.
     76::
     77if not exist %JAVA% (
     78    echo. Could not find %JAVA%. Please ensure that the variable JAVA
     79    echo. refers to a path that exists.
     80    goto end
     81)
     82%JAVA% -cp "%_I2PHOME%\lib\i2p.jar" net.i2p.util.EepGet %1 %2 %3 %4 %5
     83
     84:end
Note: See TracChangeset for help on using the changeset viewer.