Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Java code written for 1.5 to work with 1.4 JRE?

I have a project that uses generics and a few Java 1.5/6 bits and pieces. Is it possible to compile this code to work on a system running a 1.4 JRE?

I use an ANT build script and javac task to compile the library. This builds fine while the target attribute is 1.5.

If I change the target to be 1.4 I get the following error:

generics are not supported in -source 1.4 
(use -source 5 or higher to enable generics)

So I add a source attribute and try a value of 5 and 1.5. New error:

javac: source release 5 requires target release 1.5

Am I going to have to go through all my code and change the 1.5 stuff to make this work?

like image 534
Adrian Hope-Bailie Avatar asked Jun 10 '09 10:06

Adrian Hope-Bailie


People also ask

How do I compile a Java program with a specific version?

If you need to compile Java to run on an older Java platforms, the simplest approach is to install a JDK for the oldest version you need to support, and use that JDK's compiler in your builds. You can also compile with a newer Java compiler, but there are complicated.

How do I compile a Java file?

Open a command prompt window and go to the directory where you saved the java program. Assume it's C:\. Type 'javac MyFirstJavaProgram. java' and press enter to compile your code.

What compiler is used for Java?

javac - Java programming language compiler.

What is Xlint?

-Xlint:cast This option can be used to have the compiler warn the developer that a redundant cast is being made. Here is a code snippet that would get flagged if -Xlint, -Xlint:all, or -Xlint:cast was provided to javac when compiling the source.


1 Answers

I've not used either of these solutions, but there is

  1. Retroweaver
  2. specifying the unsupported -target jsr14 may work
  3. Retrotranslator
  4. Declawer
  5. JBossRetro

You might also find javac -XD-printflat useful (though take care not to overwrite your original source).

like image 183
Stephen Denne Avatar answered Nov 10 '22 08:11

Stephen Denne