Skip to content
Advertisement

JPackage Wrong Version (%JAVA_HOME% set to correct directory)

Please help. I’m having issues syncing up my JDK and jpackage versions for creating standalone java programs. The JDK version and the runtime version being included with jpackage are mismatched (JDK16 programs being paired with JDK15 runtimes).

Typing java -version into the command line, it matches up with the current %JAVA_HOME% environment variable configuration, showing JDK16.0.2 (located at C:Program FilesJavajdk-16.0.2). This is working correctly.

However the problem becomes more apparent when I type jpackage --version, it reports that it’s using JDK15.0.1 – which as far as I know, I’ve never installed and I’m unsure of where it’s running from. This is a problem, since I need to be able to build Java16 programs with jpackage. As it is now, this results incompatible runtimes and JAR files.

enter image description here

I’ve been googling to no avail. I can’t compile my JDK16 programs into installers because it keeps trying to use JDK15.0.1 for the runtime.

For now, I’ve managed to bypass this strange and seemingly locked configuration by accessing JDK16’s jpackage exe manually this way and adding the commands after:

“C:Program FilesJavajdk-16.0.2binjpackage.exe”

Any advice is helpful. Perhaps this temporary workaround will be helpful to anyone else with the same problem down the line.

Advertisement

Answer

Use the Windows where command to find out what the jpackage command is actually resolving to. It seems clear that jpackage without the full path name is resolving to jpackage in a different installation of Java.

Note that %JAVA_HOME% does not determine how the Windows cmd.exe resolves commands. Command resolution is done according to %PATH%.

The symptoms you describe:

  • jpackage says %JAVA_HOME% is incorrect but %JAVA_HOME% refers to Java 16
  • jpackage -version says Java 15 (not Java 16)
  • "C:Program FilesJavajdk-16.0.2binjpackage.exe" works

are all consistent with your %PATH% being incorrect … and that you do have a Java 15 installation on your machine, and it is on the %PATH% ahead of, or instead of the Java 16 installation you are trying to use.

Note jpackage is no longer an “incubator” tool in Java 16. It has been promoted to full support; see JEP 392: Packaging Tool. So the warnings about incubator mudules are also consistent with jpackage resolving to the wrong Java installation.


This really boils down to understanding what the Windows %PATH% variable is and how it effects the behavior of Windows command shells. (It is analogous to $PATH in Linux, UNIX and Mac OSX command shells.)

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement