简体   繁体   English

使用Java环境变量指向备用Java文件夹

[英]Using Java environment variables to point to alternate Java folder

My company's software utilizes Java Access bridge to function correctly. 我公司的软件利用Java Access桥正常运行。

We found that every time that Java updates itself, we have to once again re-install the Access Bridge components. 我们发现,每次Java更新自身时,我们都必须再次重新安装Access Bridge组件。

Is there a way to use an environment variable to point to either the Java Access Bridge or Java JRE to a folder that I can protect from getting updated? 有没有一种方法可以使用环境变量将Java Access Bridge或Java JRE指向我可以防止更新的文件夹?

When you update Java it installs it in a new folder and %JAVAHOME% changes. 更新Java时,它将Java安装在新文件夹中,并且%JAVAHOME%更改。 JAVAHOME on my systems is set to C:\\Program Files\\Java\\jdk1.7.0_13 and when I update that 13 is going to change to a 14 . 我系统上的JAVAHOME设置为C:\\Program Files\\Java\\jdk1.7.0_13 ,当我更新时, 13将更改为14

Now the problem is that when you install Java Access Bridge files get copied into varies folders including %JAVAHOME%. 现在的问题是,当您安装Java Access Bridge时,文件被复制到包括%JAVAHOME%在内的各种文件夹中。 So when you update Java the new Java home folder doesn't have the Java Access Bridge components. 因此,当您更新Java时,新的Java主文件夹没有Java Access Bridge组件。

There is really nothing you can do except reinstall Java Access Bridge. 除了重新安装Java Access Bridge,实际上您无能为力。

See the installation doco at http://docs.oracle.com/javase/accessbridge/2.0.2/setup.htm#installing-jab-64-bit . 请参阅位于http://docs.oracle.com/javase/accessbridge/2.0.2/setup.htm#installing-jab-64-bit的安装文档。

This is the batch file we went with: 这是我们使用的批处理文件:

@echo on
cd /d %~dp0

rem case sensitive jre - finds juice Java folder and puts to temp.txt into temp folder 
:CHKFLEX
set temp1=%LOCALAPPDATA%\Juice\Flex
dir /AD /b %temp1% | find "jre" > %temp%\temp.txt

rem didnt find the jre folder in juice
if %errorlevel% NEQ 0 goto notfound

rem create environment variable to path found and written to temp.txt
for /f "delims=" %%x in (%temp%\temp.txt) do set temp2=%%x

rem path to juice subfolder created
set temp1
set temp2
set "_prog=%temp1%\%temp2%"

rem copy if files aren't there already
:x86
Set JAVAHOME32=%_prog%
@echo on
if exist "%JAVAHOME32%\bin\JavaAccessBridge-32.dll" goto theend
copy WindowsAccessBridge-32.dll    %WINDIR%\SYSTEM32
copy JavaAccessBridge-32.dll       %JAVAHOME32%\bin
copy JAWTAccessBridge-32.dll       %JAVAHOME32%\bin
copy accessibility.properties   %JAVAHOME32%\lib
copy access-bridge-32.jar       %JAVAHOME32%\lib\ext
copy jaccess.jar          %JAVAHOME32%\lib\ext

goto theend

rem Juice JRE folder not found
:notfound
echo "Alternate JRE folder not found..."

:theend
pause

Although we did have a more advanced batch file that can copy to both the Juice folder and to the Java folder by checking the registry for the java home path. 尽管我们确实有一个更高级的批处理文件,可以通过检查注册表中的Java主目录路径将其复制到Juice文件夹和Java文件夹中。 Here is that one: 这是一个:

@echo on
cd /d %~dp0

:REGVAL
FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY "HKLM\Software\JavaSoft\Java Runtime     Environment" /v CurrentVersion') DO set CurVer=%%B
FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY "HKLM\Software\JavaSoft\Java Runtime Environment\% CurVer%" /v JavaHome') DO set JAVA_HOME=%%B
Set JAVA_HOME

:CHKFLEX
set temp1=%LOCALAPPDATA%\Juice\Flex
dir /AD /b %temp1% | find "JRE" > %temp%\temp.txt

if %errorlevel% NEQ 0 goto notfound

for /f "delims=" %%x in (%temp%\temp.txt) do set temp2=%%x

set temp1
set temp2
set "_prog=%temp1%\%temp2%"

pause

if not exist "%systemdrive%\Program Files (x86)" (
    goto x86
) else (
    goto x64
)

:x86
Set JAVAHOME32=%_prog%
@echo on
if exist "%JAVAHOME32%\bin\JavaAccessBridge-32.dll" goto x86_next
copy WindowsAccessBridge-32.dll    %WINDIR%\SYSTEM32
copy JavaAccessBridge-32.dll       %JAVAHOME32%\bin
copy JAWTAccessBridge-32.dll       %JAVAHOME32%\bin
copy accessibility.properties   %JAVAHOME32%\lib
copy access-bridge-32.jar       %JAVAHOME32%\lib\ext
copy jaccess.jar          %JAVAHOME32%\lib\ext

:x86_next
if exist "%JAVA_HOME%\bin\JavaAccessBridge-32.dll" goto theend
copy JavaAccessBridge-32.dll %JAVA_HOME%\bin
copy JAWTAccessBridge-32.dll %JAVA_HOME%\bin
copy accessibility.properties %JAVA_HOME%\lib
copy access-bridge-32.jar %JAVA_HOME%\lib\ext
copy jaccess.jar          %JAVA_HOME%\lib\ext

goto theend


:x64
Set JAVAHOME32=%_prog%
Set JAVAHOME64=%_prog%
@echo on
if exist "%JAVAHOME64%\bin\JavaAccessBridge-64.dll" goto x64_next
copy WindowsAccessBridge-32.dll %WINDIR%\SYSWOW64
copy WindowsAccessBridge-64.dll %WINDIR%\SYSTEM32
copy JavaAccessBridge-64.dll    %JAVAHOME64%\bin
copy JAWTAccessBridge-64.dll    %JAVAHOME64%\bin
copy accessibility.properties   %JAVAHOME32%\lib 
copy access-bridge-64.jar       %JAVAHOME64%\lib\ext
copy jaccess.jar %JAVAHOME64%\lib\ext

:x64_next
if exist "%JAVA_HOME%\bin\JavaAccessBridge-64.dll" goto theend
copy JavaAccessBridge-64.dll    %JAVA_HOME%\bin
copy JAWTAccessBridge-64.dll    %JAVA_HOME%\bin
copy accessibility.properties   %JAVA_HOME%\lib
copy access-bridge-64.jar       %JAVA_HOME%\lib\ext
copy jaccess.jar %JAVA_HOME%\lib\ext
goto theend

:notfound
  echo "not found..."

FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY "HKLM\Software\JavaSoft\Java Runtime Environment" /v CurrentVersion') DO set CurVer=%%B
FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY "HKLM\Software\JavaSoft\Java Runtime Environment\%CurVer%" /v JavaHome') DO set JAVA_HOME=%%B

set CurVer
Set _prog=%JAVA_HOME%
set _prog

if not exist "%systemdrive%\Program Files (x86)" (
    goto x86
) else (
   goto x64
)


:theend

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM