2

If I run C:\Program Files\java\jdk1.7.0_40\bin\javap javafx.application.Application I am met with a Error: class not found: javafx.application.Application.

If I run Netbeans, it has a Java 7 platform and a JavaFX platform, both of which have the same settings (same platform folder, same classes, same javadoc), so I would assume both platforms would behave the same. If I create a new Java project, import javafx.application.Application gives an error package javafx.application does not exist but creating a new JavaFX project sets up a project which uses a bunch of JavaFX stuff without any errors.

Being Java 7u40, it should have JavaFX 2.2.40 built in, yes? No? See Oracle JavaFX Release Documents

If I can get JavaFX behaving, I will be using it in a normal Java project in Netbeans which already exists and it will be embedded into an existing Swing GUI, not a new JavaFX project.

I have seen other similar questions here on Stack Overflow, but they at least seem to be able to compile and run their applications and are met with runtime errors or unexpected behavior. I cannot even get to that point.

How do I use JavaFX in my Java application under 7u40, since Oracle says JavaFX 2.2.40 should be included? Should I not expect to be able to include javafx package normally as I do any other built in Java package?

Loduwijk
  • 1,950
  • 1
  • 16
  • 28
  • I believe your assumption is incorrect. I would say create a new JavaFX project and reference it from your existing project, or copy your existing code into it. – colti Jan 14 '15 at 21:20

1 Answers1

2

JavaFX is included in Java 7, but is not on the classpath by default. If you don't want to create a JavaFX project, you need to add the jfxrt.jar file to your project manually; it is in JAVA_HOME/jre/lib directory.

If you are running from the command line, you will need

java -cp JAVA_HOME/jre/lib/jfxrt.jar:. com.example.MainClass

If you upgrade to Java 8, then the jfxrt.jar file is on the classpath (it is moved to JAVA_HOME/jre/lb/ext).

James_D
  • 201,275
  • 16
  • 291
  • 322
  • Thank you. You answered my specific question better than the answers which this one was marked duplicate as, specifically the "isn't it included now? (see oracle documents)" Still not answered is the issue where the Java and JavaFX platforms seem identical in Netbeans, but I have found that there is a "Enable JavaFX" checkbox checked for the JavaFX platform; that must do some special setup on top of the normal stuff. – Loduwijk Jan 15 '15 at 16:17