Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8030761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:52:32+00:00 2026-06-05T00:52:32+00:00

I am trying a very simple use of JavaFX using a simple set of

  • 0

I am trying a very simple use of JavaFX using a simple set of lines of code which I got from another stackoverflow page (here). But, the problem is clearly not with that code but with something more fundamental in the build and run process.

Here is my code:

import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
.
.
.
Media medMsg = new Media("msg.mp3");
MediaPlayer medplMsg = new MediaPlayer(medMsg);
medplMsg.play();

At first I couldn’t get this to compile at all. Eventually I figured out that I needed to put -classpath c:\Program Files\Oracle\JavaFX 2.1 SDK\lib\rt\jfxrt.jar on my javac command line. (One obvious complex of questions here is: Why isn’t it documented in any obvious place (1) that this is needed and (2) how exactly to figure out what the path to the JavaFX installation is?!)

But, when I run the code I get:

Exception in thread "main" java.lang.NoClassDefFoundError: javafx/scene/media/Media

    at progtest.main(progtest.java:120)
Caused by: java.lang.ClassNotFoundException: javafx.scene.media.Media
    at java.net.URLClassLoader$1.run(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)
    ... 1 more

What does this mean? It looks like it doesn’t know, at runtime, how to find the class javafx.scene.media.Media. But, my %CLASSPATH% variable definitely has “c:\Program Files\Oracle\JavaFX 2.1 SDK\lib\rt\jfxrt.jar” in it.

Any ideas? Thank you in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:52:33+00:00Added an answer on June 5, 2026 at 12:52 am

    This question somewhat duplicates compile javafx 2.0 manually.

    This answer is specifically for JavaFX 2 versions before the release of Oracle Java 8. For Oracle JavaFX 8+, the JavaFX runtime is on the classpath, so you don’t need to explicitly add it when compiling or JavaFX running applications.

    Java includes JavaFX in jdk7u6 and above (for Windows and Linux) and jdk7u4 and above (for OSX).

    Download and use jdk7u6+ and you won’t need to specify the jfxrt.jar file in any classpath and all of your JavaFX related classpath issues should go away.

    Here is a link to an early binary build of jdk7u6.

    For JavaFX 2.1 on Windows you do need to include the jfxrt.jar lib in your classpath for compile (NetBeans will do this automatically if you use it’s JavaFX platform settings) and (if you haven’t packaged your app correctly using the javafxpackager or JavaFX ant tasks), also at runtime.

    JavaFX 2.1 for Linux is a pre-release (in case you are using that). For the Linux pre-release you would only have to include jfxrt.jar in your classpath at both compile and runtime if the JavaFX runtime on Linux was not set up correctly.

    Here is an example of a command line compilation and execution of a JavaFX program under windows.

    Launch an editor:

    C:\dev\test>notepad HelloWorld.java
    

    Paste the following code and save it:

    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.stage.Stage;
    
    public class HelloWorld extends Application {
      public static void main(String[] args) {
        launch(args);
      }
      @Override
      public void start(Stage stage) {
        stage.setScene(new Scene(new Label("Hello World")));
        stage.show();
      }
    }
    

    Compile and run it JavaFX 2.2:

    C:\dev\test>javac -cp "\Program Files\Oracle\JavaFX 2.2 Runtime\lib\jfxrt.jar" HelloWorld.java
    C:\dev\test>java -cp ".;\Program Files\Oracle\JavaFX 2.2 Runtime\lib\jfxrt.jar" HelloWorld
    

    For Oracle Java 8+, the explicit JavaFX classpath specifier is not required:

    C:\dev\test>javac HelloWorld.java
    C:\dev\test>java HelloWorld
    

    Note that usually rather than just compiling the code and running it, you would also package the code with javafxpackager or the javafx ant tasks. These tasks will embed a launcher class into your packaged app which will detect the version and location of the JavaFX runtime so that you don’t need to specify the jfxrt.jar location unless you want to override the default location for the platform.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use JavaFX 2 from a simple eclipse view, but I
I am trying to use a very simple buttonlist. When the page loads everything
I’m trying to use Waypoints to do a very simple scrolling effect, but for
I'm trying something very simple. Upon page load the data in content div is
I am trying to write a very simple web-based email client from scratch with
I'm trying to use a yaml config file as a very simple flat file
I'm trying to use AppWeb, and i wrote a very simple program to embed
I'm trying to add a very simple file input to my webapp which I'm
I am trying to do a very simple bash script which emulates the behavior
I'm trying to create a very simple page that contains a container, a header,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.