Question

Using a Java 1.5 compiler, when I try to compile a java class that depends on a class that was compiled with Java 1.6, I get this error:

in/javac Java15.java
Java15.java:5: cannot access Java16
bad class file: ./Java16.class
class file has wrong version 50.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
        String java16result = Java16.test();
                              ^
1 error

The reverse works (Using a Java 1.6 compiler, I can link with a Java 1.5 class.)

Is there any sort of workaround for this?

Was it helpful?

Solution 4

The solution that worked for me was to use java.lang.Runtime.exec to execute a Java 1.6 program from a Java 1.5 program.

I realize this is probably not the best solution in most cases, but in my case (where I needed to call a Java 1.6 program from an Oracle Database using Java 1.5), it worked fine, and didn't require any changes to my current database installation.

OTHER TIPS

The "workaround" is simply not to do that - if you want to compile something with Java 1.5, compile all its dependencies with Java 1.5 as well.

I do not think what you are trying to do is possible. Java 1.6 has features that Java 1.5 does not know about and therefore would not know how to execute them.

Use the java 1.6 compiler and runtime.

You could also decompile the 1.6 code and recompile it with a 1.5 compiler.

I believe there's only one small difference between 1.5 and 1.6 class files. You can probably change the magic bytes at the start of the .class file to 1.5 and have it work. There's no guarantee though and I wouldn't do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top