tags:

views:

330

answers:

6
+5  Q: 

java 1.5 to 1.4

What is the best way to convert existing jar (without source) written in java 1.5 into java 1.4.x?

+1  A: 

You could decompile it, then recompile. You'll probably have to fix incompatibilities by hand. Here's a thread on java decompilers.

sblundy
A: 

My gut instinct would be to decompile the jar, then recompile as 1.4.

If there are no 1.5 specific API calls in the decompiled code, that should work fine. If there are, you will need to re-engineer those sections to work in the earlier java version.

RodeoClown
+10  A: 

Take a look at Retroweaver. It will convert the classes or jar so that it can be run using a 1.4 JRE. Depending on the 1.5 features used, you won't need any additional retroweaver run-time.

Retroweaver uses byte code enhancement. It sounds mysterious but it works.

David G
A: 

As well as decompiling, you'll likely have to refactor a few things in the source code - enums, generics (I don't think the generics will be in the decompiled code but that probably means you'll be missing some casts), boxing/unboxing, etc. etc.

Steve B.
+1  A: 

as Rodeoclown said,
1) unzip the JAR

2) use a decompiler like jad(http://www.kpdus.com/jad.html) using options like these jad -d src -f -ff -s .java -space -t4 ***.class

3) and from the generated source files, compile them using JDK 1.4's javac.

4) if the 1.4 compiler works OK, rebundle into new jar

5) if 1.4 compiler has issues, you need to use
retroweaver(http://retroweaver.sourceforge.net/index.html).
That might work in some cases BUT if the class expects changes in JVM, then you're in a tough spot. If the classes uses new threading facility, you can use the JDK 1.4 version of util.concurrent from http://g.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html.

Good Luck!

anjanb
+2  A: 

retrotranslator is another option similar to retroweaver

Craig Angus