I am learning JavaFx and trying to make a reusable component. The project is being developed in VSCode. The project is very simple and deals with a launcher and the reusable component. I was refactoring and when adding the modules everything has stopped working and I can't continue with the refactoring.
The error displayed inside the module-info is: javafx.controls cannot be resolved to a module
. though oddly enough, if I tell Maven to update the project, on some rare occasion the error changes to tell me that the module is empty or doesn't exist.
The source code ( experimental branch) : https://github.com/Osolemio44/text-area-right This is the structure of the project:
C:\WORKSPACE\TEXT-AREA-RIGHT
├───.vscode
├───src
│ └───main
│ ├───java
│ │ └───com
│ │ └───adeso
│ │ ├───custom
│ │ └───launcher
│ └───resources
│ └───com
│ └───adeso
└───target
Module-info of the launcher:
module com.adeso.launcher {
requires transitive javafx.controls;
requires javafx.fxml;
opens com.adeso.launcher to javafx.fxml;
exports com.adeso.launcher;
}
Module-info of the component:
module com.adeso.custom {
requires transitive javafx.controls;
requires javafx.fxml;
opens com.adeso.custom to javafx.fxml;
// exports com.adeso.custom;
}
Pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.adeso</groupId>
<artifactId>text-area-right</artifactId>
<version>0.0.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17.0.2</maven.compiler.source>
<maven.compiler.target>17.0.2</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17.0.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- ============================================
============================================
= PLUGINS =
============================================
============================================ -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.adeso.launcher.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<!-- +++++++++++++++++++++++++
+ JUNIT +
+++++++++++++++++++++++++ -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>
</plugins>
</build>
</project>
After checking all the info of jewelsea, i changed the structure of my project and now it seems to work. I changed to a Maven modules project and created 1 module-info.java inside each maven module.
C:\WORKSPACE\TEXT-AREA-RIGHT
├───.vscode
├───launchermodule
│ └───src
│ └───main
│ ├───java
│ │ └───com
│ │ └───adeso
│ │ └───custom
│ └───resources
│ └───com
│ └───adeso
│ └───custom
└───nodemodule
└───src
├───main
│ ├───java
│ │ └───com
│ │ └───adeso
│ │ └───custom
│ └───resources
│ └───com
│ └───adeso
│ └───custom
└───test
└───java
└───com