Eclipse: export executable JAR file to be executed on the older JRE

Exporting an executable JAR file from Eclipse is by far the fastest way to start an Eclipse project from the command line on another computer. See this answer .

The problem is that if the JRE installed on the computer you want to run is older than the JDK used by Eclipse, you get this error:

java.lang.UnsupportedClassVersionError: test_hello_world : Unsupported major.minor version 51.0 

I know that on Eclipse I can build a project with a lower level of compliance (e.g. 1.6 instead of 1.7 ), but this does not seem to affect the exported JAR file.

Any idea on how to export the executable JAR file that will be executed on the older JRE?

+4
java eclipse executable-jar
May 24 '13 at 8:07
source share
5 answers

This procedure works for me (I tested with Java 1.2 and Eclipse Juno):

  • Create a new project.
  • Install the runtime for J2SE-1.2.
  • Create a main class that prints one line in System.out.
  • Run the project.
  • Export an executable jar.
  • Run the jar in JRE 1.2.
+1
May 24 '13 at 8:59
source share
β€” -

Using Maven , you can specify any version of the JRE. And as a result, you get the assembly of the jar file in the specified version of the JRE. For example:

 <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> 
0
May 24 '13 at 8:11
source share

Changing the level of compliance should work. You must rebuild your project. When you export Jcl eclipse, don’t compile your project only to package it, it uses already compiled files.

0
May 24 '13 at 8:14
source share

Change the "Java Compiler" settings in eclipse. Set the compiler compliance level to 1.6.

How can I create a jar for a previous version of Java?

Then export the "Runnable Jar". He will work!

0
Mar 17 '16 at 10:03
source share

I changed the level of compliance and then also had to do the following:

  • Right-click each project and open Properties-> Java Build Path-> Libraries
  • Remove the JDK you don't want, in my case JDK 8
  • Add library -> JRE library -> Choose the version you need, in my case 7
  • Java Complier -> Set the compliance level to the desired level, in my case 7
  • Click ok, repeat as necessary.
0
Aug 09 '16 at 19:51
source share



All Articles