How to prevent that java.exe is installed in Windo

2019-01-12 05:15发布

问题:

Is there a way to prevent that the Java installation routine (e.g. jdk-7u1-windows-i586.exe) copies java.exe into C:\Windows\system32 directory?

I have to install my software on a client's laptop and I don't want to break other Java applications which are already installed on the machine. In other words I want to install a private JRE which is only used by my software.

By now, I copied an already installed JRE from my computer to the client's machine.

回答1:

I discovered yesterday that there is a problem with Java versions on Windows, as you know keeping java up to date these days is critical, especially the JRE used by Internet explorer located in the Windows system32 or syswow64 folder.

You can perform a search for java in your C: drive and look at the various executable files it finds to determine if the situation applies on a specific system.

After doing some research I find that when the Java updater runs, it only updates the files installed in the JAVA home , usually located on the program files, but it does NOT update the files located in the windows system folder. As a result and since the system folder is in the default system PATH , the usage of Internet Explorer continues to use an old version of the JAVA files ( java.exe , javaw.exe , javaws.exe )

The solution is to uninstall java using the control panel uninstall programs feature, download most recent version and install again.

Cheers! Fernando



回答2:

I recently upgraded to java 8 and discovered this problem as the java version under system32 was still java 7. It stops you even running version as it complains about the registry keys

U:\>java -version
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.8', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.

Doing the following pointed me to the culprit:

U:\>where java
C:\Windows\System32\java.exe
C:\Program Files\Java\jdk1.8.0_45\bin\java.exe

I 'solved' this problem by just deleting the java under system32! I'm unsure of what consequences this will have.



回答3:

You can just provide the JRE you want to use on your software and:

  • Set the JAVA_HOME variable before you run your application
  • Point to the correct java.exe file (e.g. ..\jre1.5.0_22\bin\java <your_java_main>)

This can be done in a *.bat file for example.

After running the *.bat file you created, all other java version will be ignored and it won't matter which versions are, or will be, installed on that pc.



回答4:

I found the newest JDK still doesn't write correct code against registry. The issue is if a computer doesn't have JRE, JDK doesn't register JRE in registry correctly.

For those install JDK 1.7u72 Just add Software\JavaSoft\Java Runtime Environment as the error message indicate. And add a string entry of CurrentVersion with value 1.7. And then add Software\JavaSoft\Java Runtime Environment\1.7 and put a JavaHome string entry with value "C:\Program Files\Java\jre7". And JRE will function correctly. Blame Oracle, if you use Registry, then write correct code, otherwise don't use the Registry!



回答5:

All you have to do is go to Control Panel -> Programs Uninstall a program. Uninstall the old java updates and keep the newest java update and java development kit update. Your newest java update and java development kit update should have the same number.



回答6:

One way I would try would be to create a write-only empty file with the name java.exe into the System32 folder.