0

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?

Jay Sullivan
  • 17,332
  • 11
  • 62
  • 86

4 Answers4

4

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
3

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.

Colin D
  • 5,641
  • 1
  • 23
  • 35
0

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.

Sarel Botha
  • 12,419
  • 7
  • 54
  • 59
  • Unfortunately I need to import this into an Oracle database that is far too dependent on Java 1.5. It looks like it's either recompiling all of Oracle into 1.6 (hard), or recompiling my classes and all their dependencies with 1.5 (a little easier). – Jay Sullivan Jun 15 '12 at 18:49
  • 1
    You may be able to upgrade the Java that Oracle is using. That is probably harder than using Java 5, but you should consider it. Java 5 is very old - Java 6 was released in 2006 and Java 5 probably has many unfixed security vulnerabilities. – Sarel Botha Jun 15 '12 at 18:55
0

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.

Jay Sullivan
  • 17,332
  • 11
  • 62
  • 86