I have a client jar made-up using java 1.6 and used enum and other new features of java, my application is built on java 1.4. I want to use that client jar in my application.
Is it feasible to do ?
-
1Why do you still build applications for Java 1.4 ?paradigmatic– paradigmatic2012年03月28日 07:37:43 +00:00Commented Mar 28, 2012 at 7:37
-
1"my application is built on java 1.4": do you, for whatever reason, need it to be source compatible to 1.4 or do you need it to run on a 1.4 JRE? Because 1.4 compatible source is typically 1.6 compatible source. ;) (Unless e.g. you use the new keywords, e.g. "enum" as variable name).user1252434– user12524342012年03月28日 07:57:17 +00:00Commented Mar 28, 2012 at 7:57
5 Answers 5
Normally: no, you can't.
You could use a library/byte-code rewriter like Retroweaver to rewrite the library to be 1.4 compatible. There's also Retrotranslator which does the same thing and other tools. The last time I used Retroweaver was just after Java 5 was released, so I can't talk about it's current state.
But that will be a hack at best. Using an ancient Java version is a liability at best and you should upgrade to at the very least Java 5 as soon as possible.
Comments
Can't you upgrade to JDK1.6?
else you need to add rt.jar of JDK1.6 to your class path but that will cause conflicts for classes common to JDK1.4 and JDK1.6
1 Comment
Your client jar will need JRE 1.6. As for your application, ideally you should be able to run it on JRE 1.6 as Java is backward compatible.
So you need to port your application to JRE 6, recompile and then you should be able to use client jar.
However, upgrading and porting has it own complexity and consequences.
Comments
you could try making the jar available via a web service interface and run it as 1.6; should work, but I won't tell you it 'll be easy.
Comments
You obviously need JRE 1.6 or higher to run your library code. Due to backward compatibility the 1.4 part of your application should run on a that JRE as well. How you interact between your 1.6 lib and your 1.4 application is another question though.
Your application cannot use enums or other 1.5 features directly. If everything you directly access in your library is 1.4 compatible it should work, I think. E.g. if your application defines an interface and the library provides an implementation of that. (I.e. typical plugin pattern.) If your library's interface needs the application to use 1.5 features, e.g. pass an enum value as method parameter, that obviously won't work with your existing byte code.