Oracle JDK 11 installer & JAR file association on Windows

时光总嘲笑我的痴心妄想 提交于 2019-12-07 20:05:28

问题


I just installed Oracle JDK 11 on my Windows 10. I noticed that the PATH variable doesn't include the JDK 11 path. Also the .JAR file extension is not associated with javaw. Our users used to doubleclick JAR file to execute the client Java/SWING application. With Java 11 this doesn't work. Is this a bug or feature? I know how to set the PATH and start the application manually using the command line. I just want to make it easier for end-users. Any ideas?


回答1:


There is no Public JRE in Java 11, as there was in the previous Java versions. Don't be confused with the jre directory in previous JDK version, it's not a Public JRE. Also installers of the old Public JRE copied the java.exe and the javaw.exe programs into the C:\Windows\System32 directory that is defined in the PATH environment variable by default. They also did many other thing, like changes in your Windows registry. Installers of the old Public JRE had never changed anything in the PATH.

Official alternative to the Public JRE is a custom runtime environment that you can built by the jlink tool of the JDK. However in this case you will have no jar file at all but UNIX shell and Batch scripts.

If you don't like it you may use JDK 11 and associate the jar files in Windows Explorer with javaw.exe of JDK, instead of JRE, as described there Running JAR file on Windows




回答2:


  1. Open regedit.exe
  2. Select HKEY_CLASSES_ROOT
  3. Create new key .jar
  4. Type jarfile to default value img
  5. In HKEY_CLASSES_ROOT create new key jarfile
  6. In jarfile create key tree like jarfile DefaultIcon shell open command
  7. [Optional] Type path to icon/executable file to default value in DefaultIcon
  8. Type path to javaw.exe to default value in command like "C:\Java\jdk11\bin\javaw.exe" -jar "%1" img
  9. Now select javaw.exe when opening the program.



回答3:


I made a bat file, which contains the following:

java -jar %1

Click on a jar > open with > select your bat

If java path is set correctly (check with java -version) it will run your jar after double clicking.



来源:https://stackoverflow.com/questions/52536971/oracle-jdk-11-installer-jar-file-association-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!