0

i am trying to create javafx project in maven, i have added this dependencies

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tensorApplication</groupId>
<artifactId>billingWizard</artifactId>
<version>0.0.1-SNAPSHOT</version>


<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <javafx.version>17.0.1</javafx.version>
    <javafx.maven.plugin.version>0.0.8</javafx.maven.plugin.version>
</properties>

<dependencies>

    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>${javafx.version}</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.8</version>
            <configuration>
                <mainClass>com.tensorApplications.jBills.Main.java</mainClass>
            </configuration>
        </plugin>


    </plugins>
</build>
i have added main class and simply buiding and running i am getting lots of error, please someone could provide me better way to create maven project with javafx in eclips
Sam
  • 13
  • 3
  • Error occurred during initialization of boot layer java.lang.module.FindException: Module javafx.controls not found – Sam Jul 27 '23 at 08:03
  • 1
    Don't know if it's your only problem, but the `mainClass` should only be the fully qualified name of the class (i.e., get rid of the `.java` bit at the end). – Slaw Jul 27 '23 at 08:13
  • i did it before still giving error – Sam Jul 27 '23 at 08:17
  • 2
    Also consider a maven _archetype_, illustrated [here](https://stackoverflow.com/a/76276885/230513). – trashgod Jul 27 '23 at 11:50
  • 1
    If you want to consider using an IDE like Netbeans, [this](https://stackoverflow.com/a/73611206/2423906) can help. – SedJ601 Jul 27 '23 at 14:52
  • You tagged this both JavaFX and Swing. Do **not** mix those two technologies when you are first starting to develop UIs. – jewelsea Jul 28 '23 at 06:48
  • thank u very much for all ur help guys – Sam Jul 28 '23 at 12:28

1 Answers1

2

I'll assume that your project is structured in the conventional way for Maven projects, with Java sources in src/main/java, and resources in src/main/resources.

Here is a simple Maven pom.xml for a JavaFX 17 application:

<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.tensorApplications</groupId>
<artifactId>billingWizard</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <javafx.version>17.0.1</javafx.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>${javafx.version}</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
        </plugin>
        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.8</version>
            <configuration>
                <mainClass>com.tensorApplications.billingWizard.Main</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

The main class configuration in the javafx-maven-plugin should just be the fully qualified name of the class (package.classname), without the .java extension.

In your Main.java file (which should be located in the package com.tensorApplications.billingWizard), you need to extend from javafx.application.Application and override the start method. This is a simple example:

package com.tensorApplications.billingWizard;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(new Scene(new Label("Hello World!"), 300, 250));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

To compile: mvn compile

To run: mvn javafx:run

You should also refresh your Eclipse project after making changes to the pom.xml file : right-click on the project in the Project Explorer and select Maven > Update Project....

Ahmet Duzduran
  • 116
  • 1
  • 4
  • man you are god thank u very much, i have one another doubt, i want to create mutiple windows, like if i click on home it takes me to home window, when click on addOrders take me to order, should i use pans or tabs what is professional way – Sam Jul 27 '23 at 09:31
  • TabPane might be a good choice. Each tab in the TabPane would represent a different section of your application – Ahmet Duzduran Jul 27 '23 at 10:22
  • @Sam it is good to ask other questions as questions, to get better chances at applicable answers. In general don’t create more windows (e.g. framed stages or dialog windows) unless you really need to. Instead change content inside a single window. TabPane will work for that, as will a browser style model with forward/back navigation or a breadcrumb header, or an app menubar or [hyperlink section](https://stackoverflow.com/questions/13556637/how-to-have-menus-website-style-navigation-links-in-java-desktop-application/13574231#13574231). – jewelsea Jul 28 '23 at 06:44