"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Compile JavaFX Code using the Command Line in Java 7, 8 (Oracle and OpenJDK)?

How to Compile JavaFX Code using the Command Line in Java 7, 8 (Oracle and OpenJDK)?

Published on 2024-11-12
Browse:464

How to Compile JavaFX Code using the Command Line in Java 7, 8 (Oracle and OpenJDK)?

Compile Code Using JavaFX 2.0 via Command Line

To compile code using JavaFX from Windows, you must leverage the Java Compiler and specify the correct classpath.

Java 8 (Oracle and OpenJDK)

Oracle Java 8 and Newer: JavaFX classes are included in the default runtime classpath, allowing you to compile and run code using:

javac Fxservidor.java
java Fxservidor

OpenJDK 8: JavaFX sources require compilation and inclusion of the resultant jfxrt.jar in the classpath:

javac -classpath "$JAVAFX_SDK_HOME/rt/lib/jfxrt.jar" Fxservidor.java
java -classpath "$JAVAFX_SDK_HOME/rt/lib/jfxrt.jar:." Fxservidor

Java 7 (Including JavaFX 2.x)

For Java 7, the process is slightly different:

"%JDK_HOME%\bin\javac" -classpath "%JAVAFX_SDK_HOME%\rt\lib\jfxrt.jar" Fxservidor.java
java -classpath "%JAVAFX_SDK_HOME%\rt\lib\jfxrt.jar;." Fxservidor

Tips:

  • JAVAFX_SDK_HOME and JDK_HOME should be adjusted to your installed locations.
  • Append ;. (or :. for Unix) to the execution classpath to include the current directory.
  • Use a modified version of the code for compilation:
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 Fxservidor extends Application {
    public static void main(String[] args) {
        launch(args);
    }
    @Override public void start(Stage primaryStage) {        
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3