简体   繁体   中英

Eclipse Java version not same as compiled Jar

I have a Java Application on Eclipse using jdk1.7.0_72

I am having an issues when running a project from a runnable jar, the application works perfectly when ran from Eclipse. The application uses a cacert which for some reason fails when I use the runnable jar. What I have noticed is that the java version of the runnable jar is different when I run it from Eclipse. This is causing issues.

Here is a snippet of the system properties when I run from Eclipse:

**sun.boot.library.path=C:\Program Files\Java\jdk1.7.0_72\jre...
java.vm.version=24.72-b04
java.runtime.version=1.7.0_72-b14
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files\Java\jdk1.7.0_72\jre…
java.library.path=C:\Program Files\Java\jdk1.7.0_72\bin…**

Here is a snippet of the system properties when I run from JAR:

**sun.boot.library.path=C:\Program Files\Java\jre7\bin
java.vm.version=24.75-b04
java.runtime.version=1.7.0_75-b13
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files\Java\jre7\lib\endorsed
java.library.path=C:\Program Files\Java\jre7\bin;C:\Win…**

How can I make the JAR use the same version that Eclipse uses?

Also when I run java -version I get this: "1.7.0_72" When I click on About Java, I get this: "1.7.0_75-b13"

If you run a JAR it'll use the Java version you set up on the PATH variable. If you run it from Eclipse you can tell Eclipse which version to use. As you can see the library.path variable is different, so you're loading a different Java in each case.

You can either set the proper Java version in the PATH variable or set it in Eclipse in the Preferences - Java - Installed JRE's menu.

It looks like you have at least two Java version installed on your machine.

  1. Java 1.7.0_72-b14 is configured in your Eclipse
  2. Java 1.7.0_75-b13 is configured in your PATH

You can change the java in your environment system variables according to this guide: https://docs.oracle.com/javase/tutorial/essential/environment/paths.html

You are most definitely using different JRE's.

You have both the JDK and the JRE installed. It just so happens that the JDK has an internal JRE which you can see in the first line:

**sun.boot.library.path=C:\Program Files\Java\jdk1.7.0_72\jre... 

The JRE is installed here

C:\Program Files\Java\jre7\bin

Your best option is to point Eclipse to execute your JAR using the installed JRE since the other option is to require the JAR to use the Eclipse JDK/JRE which would be problematic if you wanted to distribute the JAR to machines that didn't have Eclipse installed.

In Eclipse you can designate multiple JRE's and name them, create a new one and give it this path, then you can go to your project's run options and tell it to use this library when running your JAR.

" The java version of the runnable jar " cannot be different because of different execution environments: it's the JVM version.

The issue is that the jar is compiled with an higher version than the execution environment.

In the Eclipse IDE :

  • in Window / Preferences go to Java/Installed JREs
  • add your 1.7.0_72-b14 JRE
  • check the newly added JRE as the default for the workspace

Clean/recompile the project an re-export the jar file with File / Export / jar file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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