How to use Java 6 to build a java project for the Java 1.4 library?

I have a project originally written for Java 1.4, but I only have Java 6 on my Mac, and I can't install Java 1.4

Usually, I use this line to compile:

javac -source=1.4 -target=1.4 MyClass.java

However, MyClass Java implements Java sql. Resultset interface, which adds several new methods in Java 6, so I get the following compilation errors:

MyClass is not abstract and does not override abstract method
updateNClob(java.lang.String,java.io.Reader) in java.sql.ResultSet

I can't simply implement the missing method because many use generics, which is not available in Java 1.4

It seems that the solution is to get and compile Java 1.4 jars So I have a few questions:

>Is there a better way? > How to specify my java 1.6 javac? I want to use 1.4 jars instead of Java 6 jars? > Will this work, and if so, will the project run on Java 1.4 and Java 6? > How do I do this in Maven?

thank you!

Solution

Your situation seems artificial I will try my best to simplify the problem First, I'll ignore your question about Maven

So let me start with some facts:

-Source = 1.4 means: Dear compiler, please accept the language structure provided only by javac of JDK 1.4 - not library functions

-Target = 1.4 means: Dear compiler, please write class files in binary file format, which is compatible with JRE 1.4

I collected your interest in JDK 1.4's compatibility when loading, that is, you want JDK 1.4 to load the class files generated in your settings Is that right?

Do you also want to support source compatibility? Do you want others to compile your code on JDK 1.4?

If the answer to the previous question is yes, I will try to install JDK 1.4 on OS X It supports multiple installed jdks So I'm pretty sure it's possible If you do not choose to use:

-source=1.4 -target=1.4 -bootclasspath=[path/to/1.4.jar]

Be careful not to use - xbootclasspath This changes the boot classpath of the JVM executing javac

If the answer to the above question is No You can handle - source = 1.4, which allows you to use generics and other Java 5 enhancements in your code However, you must still provide binary compatibility using the following methods:

-target=1.4  -bootclasspath=[path/to/1.4.jar]

Another option is to use retroweaver

After Rereading your question, I would like to add that you must master the JDK 1.4 variant of JDBC class files Otherwise, you will encounter the compiler error you displayed in the problem

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>