I’ve got a project that was originally written for Java 1.4, but I only have Java 6 on my Mac and I cannot install Java 1.4.
Normally, I’d use a line like this to compile:
javac -source=1.4 -target=1.4 MyClass.java
However, MyClass.java implements the java.sql.ResultSet interface, which added several new methods in Java 6, so I get compile errors like:
MyClass is not abstract and does not override abstract method
updateNClob(java.lang.String,java.io.Reader) in java.sql.ResultSet
I cannot simply implement the missing methods because many use generics, which are not available in Java 1.4.
It seems a solution would be to obtain and compile against the Java 1.4 JARs. So, I’ve got a few questions:
- Is there a better way?
- How do I specify to my Java 1.6
javacthat I’d like to use the 1.4 JARs instead of the Java 6 JARs? - Will this even work, and if so, will the project run on Java 1.4 as well as Java 6?
- How do I do this in Maven?
Thanks!
Your situation seems to be quite contrived. I’ll try to simplify matters. At first, I am going to ignore your question about Maven.
So let me first state some facts:
-source=1.4means: Dear compiler, please accept only language constructs — not library features — which were available with javac of JDK 1.4.-target=1.4means: Dear compiler, please write class files in a binary file format which is compatible with a JRE 1.4.I gather that you are interested in load-time compatibility with JDK 1.4, i.e. you want that the class files produced in your setup can be loaded by JDK 1.4. Is that right?
Do you also want to support source compatibility? I.e. do you want to allow others to compile your code on a JDK 1.4?
If the answer to the last question is yes, I would try to install JDK 1.4 on OS X. It supports multiple installed JDKs. So I am pretty sure it is possible. If that is no option use:
Note, do not use -Xbootclasspath. This changes the boot classpath of the jvm executing javac.
If the answer to the above question is no. You can dispose of
-source=1.4allowing you to use generics and other Java 5 enhancement in your code. But you still have to provide binary compatibility by using:Another option would be to use Retroweaver.
After re-reading your question, I’d like add that you have to get hold of JDK 1.4 variant of the jdbc class files. Otherwise you’ll run into the compiler errors you’ve shown in your question.