How to run JavaFX in Eclipse and fix module path

Many of us facing problems for JavaFx in eclipse part.So here we will see how we can fix the problem for running out client side application on Eclipse.

What is JavaFx ?

JavaFX is a set of all graphics and media packages that helps  developers to create,design, test, debugging, and deploy the  client side applications that operate consistently across various platforms.


Follow  these steps as these are the required steps for runnig  run JavaFX  from Eclipse.
2 Install JDK 8 or later version as above later version of JDK already JRE is embedded into that zip file no need to install it separately and set class path for JDK and JRE from https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
3 Add Java  as an installed JRE to Eclipse:
        Eclipse -> Window -> Preferences -> Java -> Installed JREs -> Add.
4 Download JavaFX  from https://gluonhq.com/products/javafx/.
5 Create a User Library: 
Eclipse -> Window -> Preferences -> Java -> Build Path -> User Libraries -> JavaFxand  include the jars under the lib folder from JavaFX sdk..
6 Create a Java project. You don't need to add a module-path class. Make sure that you select Java 11 and you add the JavaFX  library to the project's modulepath.
7 Add a package javafx and the main application class HelloFX:

package application;
 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 static void main(String[] args) {
        launch(args);
    }
     @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
           @Override
            public void handle(ActionEvent event) {
                System.out.println("Hello World!");
            }
        });
        
         StackPane root = new StackPane();
        root.getChildren().add(btn);
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
  ]}

How to create JavaFx Project?

1.Click on File and select Project.Then give project name here and select jdk 8 or later version and JavaSE-1.8.




2. Slect JavaFx Project and click on Next button.



3. See default folder is Sample/bin and click on Finish.




4.Now go to Project folder created with name Sample and right click it select Properties.and click on 
Java Build Path.





5.Go to Window-Preferences Select Build path-Add New User Library type JavaFx. Now Add external jars and click on Apply and Close.






5.Now go to project folder Sample right  click and select properties. Select Arguments.Type this in VM arguments:

--module-path  D:\javafx-sdk-11.0.2\lib  --add-modules=ALL-MODULE-PATH








6.
Select Depedencies and paste the address of lib folder of JavaFx sdk.








7. Click on Run.Your program will successfully run.








Comments