简体   繁体   中英

Java backward compatibility issue - bytecode for JDK 6 not running in JRE 6

In the computer used for development, I have Java 8 installed. So in order to make my application compatible with older Java versions, I went as far back as possible when compiling the code. But still I get

Could not find the main class: mypackage.MyClass. Program will exit.

This is my development environment:

> java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) Client VM (build 25.111-b14, mixed mode, sharing)

in Netbeans, I've compiled the project using

Project Properties->Sources->Source/Binary Format: JDK 6

and indeed I get:

> javap -verbose MyClass | "version"
  minor version: 0
  major version: 50

Major 50 means java 6, from here .

The application runs fine in my development machine. However, when I try to run my jar file in another machine which has

> java -version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Java HotSpot(TM) Client VM (build 20.12-b01, mixed mode)

and I get this:

> java -jar MyClass.jar
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 12 more
Could not find the main class: mypackage.MyClass. Program will exit.

Shouldn't it run fine if the computer has Java 6 and the compiled byte code also is java 6 compatible?

Any help much appreciated.

The reason to this is probably because Java FX was not bundled into JRE/JDK 6.

I was unable to find the relevant package in the package overview summary as well as this states that

JavaFX is now part of the JRE/JDK for Java 8 (released on March 18, 2014) and has the same numbering, ie, JavaFX 8.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM