Home >Java >javaTutorial >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)?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-02 08:05:04639browse

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:
<code class="java">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) {        </code>

The above is the detailed content of How to Compile JavaFX Code using the Command Line in Java 7, 8 (Oracle and OpenJDK)?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn