JAVA compilation: compile the new JVM version and run it on the old version

Here's a little explanation for my problem.

I have an application that was compiled with java 1.5. This app is installed on 2000 pcs. (Blockboxes) installed in client packages. My app drawer is updated frequently to add new feature and fixes, but for technical reasons it is not very easy to update the java version, so I have to keep using Java 1.5 on these existing machines.

Several months ago I had a request for a new requirement for this application. To accomplish this task, I have added the use of Hazelcast in this application.

My problem is if: - Hazelacast java file requires Java 1.6 or higher, so I have to compile my application with 1.6 - New functionality using hazelcast will only be activated on demand via new option settings. This means that it will not be used in the already installed 2000 black boxes. - All new black boxes will be installed with Jave 1.6 or higher to use Hazealcast functionality.

My problem is that I want to have a unique source and unique version of my application for old drafts using Java 1.5 and newer black boxes using 1.6 or higher.

In the beginning, my idea was to always compile with version 1.5 and make sure the new functionality will only be activated in blockbuses using java 1.6 or higher. This option doesn't work because when I compile with 1.5 the compiler complains that the Hazelcast jar file requires 1.6 :(

The second option is to compile with 1.6, but then I cannot be sure that my application will work correctly in all black boxes using 1.5 .:(

I would like to know if anyone here knows how to solve this problem?

Just let me know if my explanation is not clear;)

Thanks in advance for your help.

+3


source to share


2 answers


JVM backward compatibility. You can run almost all code from Java 1 to Java 8.



So the best way is to use option two. Compile it with 1.6 on some test machines. And if it works (which it most likely will), you don't need to make big changes to the application.

+1


source


You can compile your code to Java 1.5 bytecode using JDK 1.6, just take care of the following:

  • -source=1.5

    and -target=1.5

    compiler options

  • bootclasspath should point to rt.jar from JRE 1.5



See this post for more information: http://www.draconianoverlord.com/2014/04/01/jdk-compatibility.html

The post also recommends to just build the app with the old JDK if possible. You need to figure out a different build process and exclude incompatible libraries from the classpath. If you are using Maven, consider having two files pom.xml

with an additional parent file.

+1


source







All Articles