0

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.

Raf
  • 1,628
  • 3
  • 21
  • 40
  • Do you intend to use JavaFX? Where do you use/import an `Application` class? – C-Otto Sep 20 '17 at 12:35
  • 1
    Yes. It is a JavaFX application. I guess I've found my answer here: http://www.oracle.com/technetwork/java/javafx/overview/faq-1446554.html#5 – Raf Sep 20 '17 at 12:39

1 Answers1

1

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, i.e., JavaFX 8.

Naman
  • 27,789
  • 26
  • 218
  • 353