2

Actual state

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.

Issue

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.

Source code

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>
vktop
  • 51
  • 6
  • Do you actually have JavaFX? There's a https://code.visualstudio.com/docs/java/java-gui which seems to add it, https://gist.github.com/dannyhvc/31c6cdd082cc83174a18d786fee7ec93 which seems to show the way without an addon. Also, there are other questions here as well, on StackOverflow. Shorter ones, like https://stackoverflow.com/questions/69294852/how-can-i-use-javafx-in-visual-studio-code and longer ones like https://stackoverflow.com/questions/54349894/javafx-11-with-vscode – tevemadar Aug 03 '22 at 16:49
  • 1
    Does this answer your question? [JavaFX-11 with VSCode](https://stackoverflow.com/questions/54349894/javafx-11-with-vscode) – tevemadar Aug 03 '22 at 16:49
  • Can you show your pom.xml? Where are your `module-info.java` files located? – dan1st Aug 03 '22 at 16:50
  • yes, i have java and javafx installed correctly. indeed i was working perfectly before implementing module-infos. I am adding the module-info to start learning also modularity in java. – vktop Aug 03 '22 at 17:19
  • no, it doesnt resolve the issue. – vktop Aug 03 '22 at 17:23
  • in fact when there was the first module, everything worked perfectly. but when restructuring the project and separating it into 2 different packages, at that moment the module-info stopped working well – vktop Aug 03 '22 at 18:01
  • You can’t have multiple module-info files in a single jar or single maven module. If you want to build multiple Java platform modules you need multiple maven modules. For each module the module-info is placed directly in the java directory (which is why you can only have one per maven module). – jewelsea Aug 03 '22 at 18:06
  • Follow the [Baeldung tutorial: maven-multi-module-project-java-jpms](https://www.baeldung.com/maven-multi-module-project-java-jpms) – jewelsea Aug 03 '22 at 18:10
  • “javafx installed correctly” -> I don’t understand this. You are using Maven, it downloads the JavaFX components that you need as it does other components, you don’t need to install JavaFX. – jewelsea Aug 03 '22 at 18:14
  • 1
    Having a module which doesn’t export anything doesn’t make sense. – jewelsea Aug 03 '22 at 18:17
  • As I said in the previous comment, I'm new to all this. I am not using maven modules, just a maven project. Multiple java modules cannot be defined in the same Maven Project? As I also mentioned before, I did not finish refactoring the project due to the error that the module-info gives me. As soon as I fix it, I'll finish making sense of the rest. – vktop Aug 04 '22 at 13:46
  • The idea was to have in the same project 1 java module for the reusable component and another module for a small project that starts that component and be able to see how it works. – vktop Aug 04 '22 at 13:46
  • And thus be able to create the jar only of the component and use it in other projects. Please, can you give me more information or tell me where I can consult about the fact that several java modules cannot be used in a maven project? If you use maven, do you have to use maven modules and not use java modules? – vktop Aug 04 '22 at 13:46
  • Try this command: **Ctrl+Shift+P** --> **Java: Clean the java language server workspace**. – JialeDu Aug 05 '22 at 06:53

1 Answers1

1

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
vktop
  • 51
  • 6