Table of Content

JDK and JRE mismatch

In general, the compiled class can running cross platform if there is not platform specific coding inside, however there is another condition for cross platform compile and running – JDK and JRE mismatch.

Let us say you compile class on Win 7 using J2SE 8, you will get error when running it directly on Solaris 10 which as JRE running env.

when compile class on Win7 and transfer to solaris 10, cannot run directly, one solution is recompile on J2SE 6.0 on solaris 10.

solaris10> java SwingControlDemo
Exception in thread "main" java.lang.UnsupportedClassVersionError: SwingControlDemo : Unsupported major.minor version 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: SwingControlDemo.  Program will exit.

1) one option is recompile class on Solaris 10 using local J2SE 6

solaris10> javac SwingControlDemo.java
solaris10> java SwingControlDemo
Java Accessibility Bridge for GNOME loaded.

However most of chance, you don’t want to transfer Java source code to target box Solaris 10 to recompile it.

2) another solution is precompile class as same level JDK (target box) on source box

source: Win7 J2SE 8
target: Solaris 10 J2SE 6.0

this is supported major.minor version table:

J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

on source box, you need to install both higher and lower JDK, compile class using lower JDK version which same as target box JDK version.