7

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?

1
  • Note 1.4 has finished its service life period and 1.5 is most of its way through. However "Java for Business" support is available at a price. Jun 10, 2009 at 11:55

4 Answers 4

7

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).

3
  • Second one seems to work. Now to test that the library actually works on JRE 1.4... Jun 10, 2009 at 11:14
  • 1
    jsr14 is not gonna cut it. No enum support. Retroweaver on the other hand is great. Jun 10, 2009 at 11:44
  • Thanks, I was only aware of Retroweaver until now. Most of those tools explicitly state that they can target 1.4, but as far as I can see only Retroweaver allows you to target 1.2 as well, which might be needed for J2ME development. Jul 24, 2009 at 10:53
6

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?

No.

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

Yes. But there's a way to automate that, using a tool called Retroweaver. There's no guarantee that it will catch everything though.

1

I have had good experience with Retrotranslator (retroweaver did not work well with what I was needing, cannot remember exactly what).

It worked very well for my purpose (creating JDK1.4 versions of Logback).

http://retrotranslator.sourceforge.net/

0

Generics are implemented by type erasure so they should work before generics were introduced. However you would be unable to compile the code with an older version of the compiler (I don't know why you would want to do that)

2
  • Using JDK 1.6 compiler. Just seems strange that you can specify the target version and source version but it gives an error if these aren't the same. Jun 10, 2009 at 11:12
  • You can specify an earlier source version than target version. So your 1.4 source with Enumerations called enum can still compile and work on in-service-life JDKs unmodified. Jun 10, 2009 at 11:54

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.