You say it works when you double click the JAR file (in File Explorer) but not when you run it from the PowerShell window in this folder:
C:\incubating-netbeans-11.0-bin\netbeans\ani\Tank-IQ-Display-Configurator\Tank-IQ-Display-Configurator\dist
I'm guessing you have more than one JDK installed.
If you enter the following command in the PowerShell window, it will display the paths to all the java.exe
files.
where.exe java
Windows associates file extensions with executables. Obviously, on your computer, the .jar
extension is associated with java.exe
. You can check this via Control Panel. Look for Default Apps. Hence when you double click the JAR in File Explorer the associated executable is launched.
I'm guessing that the default executable is that of JDK 11 and that either in the folder whose path I wrote above there is a java.exe
that is compatible with JDK 8 or in your PATH environment variable, the path to the JDK 8 executable comes before the path to JDK 11 executable.
So check those things, i.e.
- Default apps in Windows
- PATH environment variable
Obviously there are many different ways to rectify the situation. I don't think any one is clearly superior and the most appropriate would depend on your environment and your needs which I am unaware of since you haven't provided those details, hence I won't suggest what actions you should take in order to resolve your issue.
What you do need to do is ensure that a JAR file containing java code that was compiled to JDK 11 is run with a java.exe
from at least JDK 11.
Note that higher java versions can run classes compiled to lower versions. In other words, if your JAR was compiled to JDK 8, you could run it with JDK 11, but not the other way around (which is the cause of your error, as others have indicated).