Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Run Jar on java 7 compiled in java 8 or higher version [duplicate]

I have created a windows application using java 8 . But my client is using java 7 on his machine and not able to upgrade java on the machine.

So when i run jar on java7 compiled in java 8 it gives error so can i convert jar compatible to lower version java

like image 498
adesh singh Avatar asked Apr 12 '19 09:04

adesh singh


People also ask

Can program developed with Java 7 be run on Java 8?

Binary CompatibilityJava SE 8 is binary-compatible with Java SE 7 except for the incompatibilities listed below. Except for the noted incompatibilities, class files built with the Java SE 7 compiler will run correctly in Java SE 8.

Can newer JRE versions run Java programs compiled with older JDK versions?

For standard code, yes, it still works, but there are a few enterprise libraries that you can no longer rely on having present.

How can I change Java 7 to 8?

Go to Window -> Preferences -> Java -> Compiler and there you can change the Java version. This way, you can update your PC to Java 8 and you'll have no problem with the older projects. Well, first of all you have to install Java 8. Then, you'll have the option to select the 1.8 version.

How do I run a JAR file in Java?

You may have to restart your computer for Java to be fully implemented. Double-click the JAR file. If it's executable and you have Java installed, it should open. If it doesn't open, proceed to the next step. You may see a pop-up window asking which program you want to use to open the file. If so, click Java (TM) and then click OK.

How to get your Java 8 application to run on Java 11?

Getting your Java 8 application to run on Java 11 – in 9 easy steps Adding support for page fragments to Google Analytics the quick and easy way Move from Octopress to Github-side Jekyll Incremental synchronization of ZIP files in bandwidth-constrained environments

How to compile&run Java program without external jar?

The following example shows how to compile and run Java program in command line mode with external jars. It is developed under Linux. 1. Compile & Run Java Program Without External Jar Let's create a simple hello world program "helloworld.java". public class helloworld { public static void main (String[] args){ System. out. println("Hello!"); } }

What is a JAR file?

This wikiHow teaches you how to open and run executable JAR files on a Windows or Mac computer. JAR (Java Archive) files contain data to be used with the Java program.


Video Answer


2 Answers

You can't change a compiled jar's Java version. You have 2 option in hand.

  1. Compile the Source code using Java-7.

  2. Compile source code using Java-8 but using the following command when target vm version is java-7.

javac "Your java classes" -source 1.8 -target 1.7
like image 153
Amit Bera Avatar answered Nov 14 '22 23:11

Amit Bera


Java 7 is forward compatible with Java 8. Java 8 can be compiled so that it runs on a Java 7 VM (with -source 7 -target 7), but you can’t use any of the newer APIs. Just Compile with JAVA 7 and you would be good to go just make sure you are not using new features of java 8 like lamda

like image 40
Vaibhav Gupta Avatar answered Nov 14 '22 22:11

Vaibhav Gupta