Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: export a Runnable JAR file to be executed on an older JRE

Exporting a Runnable JAR file from Eclipse is by far the quickest way to launch an Eclipse project from command line on another machine. See this answer.

A problem is that if the JRE installed on the machine you want to run from 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 the project with a lower compliance level (e.g., 1.6 instead of 1.7), but this does not seem to affect an exported JAR file.

Any idea on how to export a Runnable JAR file to be executed on an older JRE?

like image 904
Alphaaa Avatar asked Nov 12 '22 04:11

Alphaaa


1 Answers

This procedure seems to work for me (I tested with Java 1.2 and Eclipse Juno):

  • Create a new project.
  • Set the execution environment to J2SE-1.2.
  • Create a main class that prints one line to System.out.
  • Run the project.
  • Export the runnable jar.
  • Run the jar in JRE 1.2.
like image 73
Russ Hayward Avatar answered Nov 14 '22 23:11

Russ Hayward