Problems running JavaFX application on Java 1.7u80

2020-07-25 08:22发布

问题:

I am using Netbeans 8.02 on the MAC and am creating a simple JavaFX application from the New Project Wizard.

When I set the platform to Java 1.8 it works just fine, but when I try to run it on Java 1.7u80 I get "java.lang.NoClassDefFoundError: javafx/application/Application". Behavior is the same when running from the IDE or from the command line.

Everything compiles just fine with either platform, so it does look like JavaFX is on the classpath for both platforms I have installed.

My target application will have to run on 1.7, so I cannot simply go with 1.8 and call it a day.

回答1:

If you want to run JavaFx application on Java 1.7, you need to add jfxrt.jar into your classpath manually. In Java 1.8 jfxrt.jar is in the classpath by default. So that's why you got this problem while running it on 1.7.

You should be able to add it via your IDE. You can also use some third party tools like JavaFx Maven Plugin



回答2:

It turns out I ran into this known bug in NetBeans IDE.

https://netbeans.org/bugzilla/show_bug.cgi?id=239388

It sounds like the path settings is causing the ide to use the Ant script which builds for platform V 1.8 by accident.

I changed the platform for Netbeans itself to be JDK 1.7 and now everything builds fine for 1.7 and runs the JavaFX app 100% using JDK 1.7u80.