Cannot run JavaFX application from terminal

Related searches

When I try to run a JavaFx application from the terminal, it fails to run showing Error: Could not find or load main class com.test.javafx.HelloWorld

Here is my code:

package com.test.javafx;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class HelloWorld extends Application {

    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {

            public void handle(ActionEvent event) {
                System.out.println("Hello World!");

        StackPane root = new StackPane();

 Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
 public static void main(String[] args) {

Compilation does not show any error and is successful. But trying to run the application results in Error: Could not find or load main class com.test.javafx.HelloWorld. However when I run a simple application, it runs without any errors.

Here is the javap output:

Compiled from ""
public class com.test.javafx.HelloWorld extends javafx.application.Application {
  public com.test.javafx.HelloWorld();
  public void start(javafx.stage.Stage);
  public static void main(java.lang.String[]);

I have also tried the following:

java -cp /home/itachi/mycategories/installs/devel/java/jdk/jdk1.8.0_101/jre/lib/ext/jfxrt.jar;." com.test.javafx.HelloWorld

but that doesn't work as well.

Fixed the issue


While installing some software using Linux package manager, OpenJDK JRE Headless (as a dependancy package) was installed. This was confirmed by running:

$ java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
$ java com.test.javafx.HelloWorld
Error: Could not find or load main class com.test.javafx.HelloWorld

If I run using this OpenJDK JVM, it shows the error.


Changed the PATH variable so that now Oracle's JVM is default.

$ ${JAVA_HOME}/bin/java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
$ ${JAVA_HOME}/bin/java com.test.javafx.HelloWorld => [Now the program runs]

[After Changing the ~/.bashrc file]
$ . ~/.bashrc
java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
$ java com.test.javafx.HelloWorld => [Now the program runs]
Unknown Factor

Still, I am not sure why OpenJDK JVM throws Error: Could not find or load main class com.test.javafx.HelloWorld, because running Oracle JVM from the same location renders the application.

Cannot run the JavaFX program on the terminal, but it run well on , I am trying to create a JavaFX program. The program run well on intellij. However , when I try to execute “Main.class” on the terminal. I get a� If your app is made with Java 8 (Java 1.8) containing Java FX and you do not want to change to Java 11 then you need to install Open Java 8 on your Ubuntu + install openjfx . Another solution will be to install Oracle Java 8 for Ubuntu which will contain JavaFx.

This usually happens when java cannot find your compiled classes in classpath. Try java -cp <path to .class files> HelloWorld

Cannot launch JavaFX application from command line using pkg , When I try to execute a JavaFX application in a package from command line it doesn't work and it shows an error, "Error: Could not find or load� To run the packaged application outside NetBeans IDE, go to the dist subdirectory of your application project directory and do the following: To run the application in standalone mode, double-click the JAR file. To run as a Web Start application, either click the link in the HTML page in your browser or double-click the JNLP file.

I just ran into this trying the stock JavaFX HelloWorld example, and it looks like this is a known low-priority bug with OpenJDK/JavaFX. Commenting out the "package" declaration at the top of and re-compiling lets it run without problems.

I hit this on XUbuntu 16.04/Java 1.8.0_144.

Compiling and Running from the Command-Line (Getting a Jump , We usually use an IDE to build and run JavaFX programs, but to take all of the mystery out of the process we use the command-line tools first. □ Note For this� TerminalFX is a terminal (PTY) emulator application written in JavaFX 12. We use Pty4J to get VT codes from running process and hterm.js from Chromium project to interact with Pty4J. TerminalFX is using powerful JavaFX WebView component to run hterm.js.

Getting Started with JavaFX: Deploying Your First JavaFX Application, I have installed Java using the apt install default-jre command. Any ideas? This is the error I get on running java -jar myApp.jar : Could not find or� –module-path “path/to/javafx-sdk-11/lib” adds the JavaFX SDK to the module path. –add-modules=javafx.controls –add-modules=javafx.swing adds the specific JavaFX modules needed to run the application. JPedal requires the controls module and the swing module, so those are the 2 I have added.

java - Can't execute my .jar JavaFX application, In the Ubuntu 16.04 and later default repositories JavaFX is packaged as a separate package named openjfx. To install it in Ubuntu 18.04, open the terminal and type: sudo apt install openjdk-8-jdk openjfx

Before trying to troubleshoot your application, ensure the JavaFX samples run properly. Download the JavaFX samples zip file. Double-click the JAR file, the JNLP file, and the HTML file for at least one sample to ensure it runs correctly. Validate that the java process is using your Java Runtime installed location.

  • That would not give the error message you posted in the question.
  • @James_D I have updated the answer. Hope that answers yours question.
  • Did you intend the output from java -version in the first code block to be identical to the output in the second code block?
  • @James_D Copied the wrong block and pasted. Now updated the answer
  • That makes a bit more sense. I still really don't get why it is saying it can't find the class you defined... that just sounds like the classpath is messed up. If it said it couldn't find something in javafx.* or com.sun.javafx.* it would make sense. However, it is what it is.