Reputation: 39
I have a code.jar running well in 1.7 version java, but when using another computer with linux with version 1.6 it is giving me an error, how can I run it in 1.6 version?
Upvotes: 3
Views: 20440
Reputation: 1
I have found a solution within Eclipse!
If you go to your project and right click to access the properties, there is a tab called Java Compiler. If you enable project specific properties and unclick the check box under JDK compliance, you can change the source compatibility and .class files compatibility to be 1.6.
This should fix your problem and the generated .jar file should work on both devices. I tested this by moving a file from 1.8 to 1.7 and testing on my Raspberry Pi that has OpenJDK 1.7 which worked great. I hope this helps.
Upvotes: 0
Reputation: 168825
Use the cross-compilation options when invoking javac
.
If only the -target
option is specified as recommended in most other replies, the 1.7 SDK will issue a warning about -bootclasspath
. That option requires an rt.jar
of the target JRE version (note not JDK). It allows the compiler to check that the classes, methods and attributes of the code that reference core Java SE are actually present in the rt.jar
. This is very important to ensure compatibility.
Upvotes: 3
Reputation: 330
Build the project using Java 6 in eclipse, you will need to download Java 1.6 JRE, then have eclipse point to 1.6 JRE, see: http://www.cleartoolkit.com/dokuwiki/doku.php?id=clearwiki:20.cleardatabuilder:01.setup:01.prerequisites
Now right click on your project -> Properties, click Java Compiler, uncheck "enable project specific settings", click "Configure Workspace Settings" , and select 1.6 as your compiler compliance level.
Do "the thing" to export your project again, the new jar should work.
Hope this helps.
Upvotes: 1
Reputation: 66637
I don't think you can run higher version class with lower version.
Another approach may be while compiling set target version as 1.6.
Example:
javac yourFile.java -target 1.6
Upvotes: 0
Reputation: 32391
If the code is not compiled with an older Java compatibility flag, you won't be able to run it on 1.6.
Upvotes: 1