Reputation:
What is the best way to convert existing jar (without source) written in java 1.5 into java 1.4.x?
Upvotes: 6
Views: 1153
Reputation: 13925
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!
Upvotes: 0
Reputation: 6317
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.
Upvotes: 12
Reputation: 57333
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.
Upvotes: 0
Reputation: 13828
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.
Upvotes: 0
Reputation: 61434
You could decompile it, then recompile. You'll probably have to fix incompatibilities by hand. Here's a thread on java decompilers.
Upvotes: 1