64-bit JAVA_HOME support for vncviewer-java.bat

12 views
Skip to first unread message

curts

unread,
Mar 26, 2018, 11:31:38 AM3/26/18
to TurboVNC User Discussion/Support
My work on Windows requires my JAVA_HOME point to a 64-bit JDK, but this doesn't play well with the 'vncviewer-java.bat' script, which expects JAVA_HOME to point to a 32-bit JDK if it is set. I would like to submit an enhanced launch script for consideration.

<code>
@echo off
setlocal enableextensions enabledelayedexpansion
rem Find the 32-bit JRE
if defined PROGRAMFILES(x86) (set "reg=%windir%\SysWOW64\reg") else set "reg=reg"
set "branch=HKLM\Software\JavaSoft\Java Runtime Environment"

for /f "tokens=3" %%v in ('%reg% query "%branch%" /v "CurrentVersion" ^| find "REG_SZ"') do (
    for /f "tokens=2*" %%I in ('%reg% query "%branch%\%%v" /v "JavaHome" ^| find "REG_SZ"') do (
        set "JRE32=%%J"
    )
)
echo Location of 32-bit java.exe: %JRE32%\bin

if DEFINED JAVA_HOME goto java_home_defined

set JAVA=java
goto java_home_undefined

:java_home_defined
if defined PROGRAMFILES(x86) goto java_home_64bit
set JAVA_HOME=%JAVA_HOME:"=%
if "%JAVA_HOME%"=="" (
    set JAVA=java
) else (
    set JAVA=%JAVA_HOME%\bin\java.exe
    set JAWT_PATH=%JAVA_HOME%\bin
)
if DEFINED JAWT_PATH goto jawt_path_defined

:java_home_undefined
rem This should work with Java 7 and later.
for /f "delims== tokens=2,3*" %%i in ('"%JAVA% -XshowSettings:properties -version 2>&1 | findstr sun.boot.library.path"') do set _TMP=?%%i
set _TMP2=%_TMP:? =%
if EXIST "%_TMP2%\jawt.dll" set JAWT_PATH=%_TMP2%
if DEFINED JAWT_PATH goto jawt_path_defined

rem Maybe we're using Java 6?
if EXIST "c:\Program Files\Java\jre6\bin\jawt.dll" set JAWT_PATH=c:\Program Files\Java\jre6\bin
if DEFINED JAWT_PATH goto jawt_path_defined

echo WARNING: Could not find jawt.dll.  Some features may not work properly.
goto start

:java_home_64bit
rem Check for 64-bit JAVA_HOME
if "%JAVA_HOME:~0,16%"==%PROGRAMFILES% (
    rem Cannot use 64-bit Java, unset JAVA_HOME
    echo Unset 64-bit JAVA_HOME
    set JAVA_HOME=
    set JAVA=%JRE32%\bin\java.exe
    set JAWT_PATH=%JRE32%\bin
    goto jawt_path_defined
) else (
    rem JAVA_HOME is 32-bit Java
    set JAVA=%JAVA_HOME%\bin\java.exe
    set JAWT_PATH=%JAVA_HOME%\bin
)

:jawt_path_defined
echo JAWT_PATH=%JAWT_PATH%
set PATH=%JAWT_PATH%;%PATH%
echo jawt.dll path: %JAWT_PATH%
goto start

:start
"%JAVA%" -Dsun.java2d.d3d=false -Djava.library.path="%~d0%~p0java" -jar "%~d0%~p0java\VncViewer.jar" -reqarch x86 %*
</code>

Kind regards,

Curt

curts

unread,
Mar 26, 2018, 11:40:53 AM3/26/18
to TurboVNC User Discussion/Support
Minor correction below.
if "%JAVA_HOME:~0,22%"==%PROGRAMFILES(x86)% (

    rem JAVA_HOME is 32-bit Java
    set JAVA=%JAVA_HOME%\bin\java.exe
    set JAWT_PATH=%JAVA_HOME%\bin
    goto jawt_path_defined
) else (
    rem Cannot use 64-bit Java, unset JAVA_HOME
    echo Unset 64-bit JAVA_HOME
    set JAVA_HOME=
    set JAVA=%JRE32%\bin\java.exe
    set JAWT_PATH=%JRE32%\bin
)

curts

unread,
Mar 26, 2018, 11:49:21 AM3/26/18
to TurboVNC User Discussion/Support
Oh dear, now I've posted a bad fix. Sorry for posting this prematurely - I thought I had this sorted.


On Monday, March 26, 2018 at 11:31:38 AM UTC-4, curts wrote:

curts

unread,
Mar 26, 2018, 2:37:52 PM3/26/18
to TurboVNC User Discussion/Support
OK, I think I have it sorted now so it will work correctly for both 32-bit & 64-bit JAVA_HOME on 64-bit Windows 7. Thank your for your patience.

Curt

<code>
if not "%JAVA_HOME:*Files\Java=%" == "%JAVA_HOME%" (

    rem Cannot use 64-bit Java, unset JAVA_HOME
    echo Unset 64-bit JAVA_HOME
    set JAVA_HOME=
    rem Use 32-bit JRE

    set "JAVA=%JRE32%\bin\java.exe"
    set "JAWT_PATH=%JRE32%\bin"
    goto jawt_path_defined
) else (
    rem JAVA_HOME is 32-bit Java
    set "JAVA=%JAVA_HOME%\bin\java.exe"
    set "JAWT_PATH=%JAVA_HOME%\bin"
)

:jawt_path_defined
echo JAWT_PATH=%JAWT_PATH%
set PATH=%JAWT_PATH%;%PATH%
echo jawt.dll path: %JAWT_PATH%
goto start

:start
"%JAVA%" -Dsun.java2d.d3d=false -Djava.library.path="%~d0%~p0java" -jar "%~d0%~p0java\VncViewer.jar" -reqarch x86 %*

</code>

DRC

unread,
Apr 5, 2018, 12:23:07 AM4/5/18
to turbovn...@googlegroups.com
Sorry for the delay on this. I'm working feverishly on putting out a
much-needed VirtualGL release, then I'll switch to working feverishly on
putting out a much-needed TurboVNC release. I expected to have had
TurboVNC 2.2 beta out by now, but finishing libjpeg-turbo 2.0 beta
(which was a prerequisite) took way longer than expected. Thanks for
your patience as well. :)

DRC
> --
> You received this message because you are subscribed to the Google
> Groups "TurboVNC User Discussion/Support" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to turbovnc-user...@googlegroups.com
> <mailto:turbovnc-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/turbovnc-users/7f44a79a-87cc-4b7a-90e7-13a64a93861d%40googlegroups.com
> <https://groups.google.com/d/msgid/turbovnc-users/7f44a79a-87cc-4b7a-90e7-13a64a93861d%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

curts

unread,
Apr 5, 2018, 9:21:50 AM4/5/18
to TurboVNC User Discussion/Support
One more update, because the latest 'jre-8u162-windows-i586.exe' installer includes both 32- & 64-bit JRE installations, whether you want 64-bit or not. This latest version of the launch script handles this correctly when there is no JAVA_HOME defined.


<code>
@echo off
setlocal enableextensions enabledelayedexpansion
rem Find the 32-bit JRE
if defined PROGRAMFILES(x86) (set "reg=%windir%\SysWOW64\reg") else set "reg=reg"
set "branch=HKLM\Software\JavaSoft\Java Runtime Environment"

for /f "tokens=3" %%v in ('%reg% query "%branch%" /v "CurrentVersion" ^| find "REG_SZ"') do (
    for /f "tokens=2*" %%I in ('%reg% query "%branch%\%%v" /v "JavaHome" ^| find "REG_SZ"') do (
        set "JRE32=%%J"
    )
)
echo Location of 32-bit java.exe: %JRE32%\bin

if DEFINED JAVA_HOME goto java_home_defined

set "JAVA=%JRE32%\bin\java"

DRC

unread,
May 7, 2018, 5:33:46 PM5/7/18
to turbovn...@googlegroups.com
Popping the stack on this. In my testing, the 64-bit TurboVNC Viewer
package works just fine, with no modifications, when pointing JAVA_HOME
to a 64-bit JRE. Are you attempting to use the 32-bit TurboVNC Viewer
with a 64-bit JRE? If so, then that isn't supported. Because we use
JNI, the 32-bit TurboVNC Viewer package only works with 32-bit JREs, and
the 64-bit TurboVNC Viewer package only works with 64-bit JREs. You can
co-install 32-bit and 64-bit TurboVNC Viewer packages if necessary, and
invoke the vncviewer-java.bat script for whichever one matches the JRE
specified in JAVA_HOME, but I don't really understand why you can't just
use the 64-bit TurboVNC Viewer for everything.

DRC
> --
> You received this message because you are subscribed to the Google
> Groups "TurboVNC User Discussion/Support" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to turbovnc-user...@googlegroups.com
> <mailto:turbovnc-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/turbovnc-users/7f5232b2-98bf-4a2e-9080-732f11a64d85%40googlegroups.com
> <https://groups.google.com/d/msgid/turbovnc-users/7f5232b2-98bf-4a2e-9080-732f11a64d85%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages