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
Release: 2024-11-02 08:05:04
Original
648 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template