Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I build a jar for a previous Java version?

I am trying to compile my code and run it on a different server. The problem is my JRE version is Java version "1.6.0_13" and that on the server is Java version "1.4.2".

This gives me "unrecognized class file version" exception when I try to run the jar on the server. I cannot compile my code on the server because of various dependencies I will have to set up.

So I need to know if there is a way to "use Eclipse" [this is easier than command line since it takes care of dependencies] and compile my stuff using 1.4.2 instead 1.6.0_13. Do I have to uninstall my JRE from my machine, then reinstall previous version and then compile or is there an elegant and cleaner way?

like image 556
codeObserver Avatar asked Dec 08 '10 23:12

codeObserver


People also ask

Are JAR files backwards compatible?

JAR is: the only archive format that is cross-platform. the only format that handles audio and image files as well as class files. backward-compatible with existing applet code.

How do I downgrade a JAR file?

You can try to unpack a jar file with the "jar" CLI Tool and change the Version in the Manifest file. Then you need to Repack the file again. This worked for me once with an OSGi Bundle.

Can a JAR file be modified?

You can use the JAR file editor to view or edit JAR file information that is stored in a data development project. If you make changes to JAR file information using the editor, you must deploy the JAR file to the database server again to apply the changes to the server version of the JAR file.


1 Answers

Eclipse Mars (4.5.1)


Change JDK compliance

Window > Preferences > Java > Compiler > JDK Compliance > change Compiler compliance level:

Compiler compliance level

If you want to change other details, you can uncheck "Use default compliance settings".

Press OK and in the "Compiler Settings Changed" window choose:

  • Yes if you want to build all projects from the workspace:

    Compiler Settings Changed

  • No if you want to build only one/some project(s) later

    • Select the project (click on the left side - E.g.: in the Package Explorer) > Project > Build Project

Export jar

Right click on the project (from the left side - E.g.: in the Package Explorer) > Export... > type "jar" to filter the options you have > choose what you want (probably JAR file or Runnable JAR file) > Next > add the details > Finish

like image 95
ROMANIA_engineer Avatar answered Sep 28 '22 03:09

ROMANIA_engineer