Home > Enterprise >  Compilation Error with Maven on Intellij: Module not found: processed.jcommander
Compilation Error with Maven on Intellij: Module not found: processed.jcommander

Time:12-23

I was developing some small program using selenium and javaFX. everything was going fine, when i tried my code on selenium on a project and on a JavaFX project separatedly. When i put the code together and imported all dependecies to maven, and tried to run, it keep showing this error:

[ERROR] COMPILATION ERROR :[INFO] -------------------------------------------------------------[ERROR] module not found: processed.jcommander[ERROR] module not found: processed.async.http.client

I don't know what are those modules, they were not dependecies and are not used in the code. What those modules are and why compilation error?

Here is my 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>org.example</groupId>
    <artifactId>DedoDoDida</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>19</maven.compiler.source>
        <maven.compiler.target>19</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.7.1</version>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.projectlombok</groupId>-->
<!--            <artifactId>lombok</artifactId>-->
<!--            <version>1.18.6</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>com.google.code.gson</groupId>-->
<!--            <artifactId>gson</artifactId>-->
<!--            <version>2.10</version>-->
<!--        </dependency>-->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>20-ea 11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>20-ea 11</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>19</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.6</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running -->
                        <!-- Usage: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>org.example.App</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

I tried already searching on internet and i am stuck on this problem for 2 days already, i was giving up this project but i decided to try stackoverflow. Probably some easy thing to solve that i am not being able to solve.

CodePudding user response:

This occurs because the Java Platform Module definitions used for the 4.7.1 version of Selenium software that you are using appear (to me) to be broken.

I'm working with the pom.xml you have in your application updated for:

  • The current version of the javafx-maven-plugin is 0.0.8.
  • The current non-early access (no -ea in the version) of JavaFX is 19.

And the hello world program from the selenium documentation.

package dev.selenium.hello;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class HelloSelenium {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();

        driver.get("https://selenium.dev");

        driver.quit();
    }
}

As far as I can tell (and I can't really find documentation on this), so maybe this isn't even supported at the moment, to use Selenium in a modular application, you need the following modules in your module-info.java. These were suggested by my IDE when I tried to compile the above program.

requires org.seleniumhq.selenium.api;
requires org.seleniumhq.selenium.chrome_driver;

Once that was done, a subsequent mvn:compile gives the errors from the question:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] module not found: processed.jcommander
[ERROR] module not found: processed.async.http.client

These modules are not in the transitive dependencies for selenium, so the selenium modules are broken. There are maven dependencies on the artifacts, so you can see jcommander and async-http-client jars in the library dependencies that Maven brings in, however those jars do not provide any module information, so their module names should be derived from the jar file names as "automatic modules". This means they would be referenced from a module-info.java as:

requires jcommander;
requires async.http.client;

But they are not referenced using these names.

The selenium-chrome-driver jar has:

module org.seleniumhq.selenium.chrome_driver {
    ...
    requires org.seleniumhq.selenium.remote_driver;
    ...
}

The selenium-remote-driver jar, has:

module org.seleniumhq.selenium.remote_driver {
    ...
    requires processed.async.http.client;
    requires processed.jcommander;
    ...
}

So those are the wrong names, the modules with the processed. prefix do not exist, so the simple HelloSelenium application is not usable if you define module-info.java.

The only workaround I can advise for now is to make your application non-modular by not defining a module-info.java (i.e. delete the module-info.java file if you have one in your project.).

However, because JavaFX needs to be on the module path, you then also need to either:

  1. Use a JDK which includes JavaFX (e.g. "Full JDK" from liberica), (this is the option I recommend) OR
  2. Add VM options to set the module path and add the JavaFX modules at compile and execution time (as specified at openjfx.io).

I also advise filing a bug for the selenium project to fix their broken module definitions in the selenium-remote-driver jar.

  • Note: I don't know how the selenium project bug reporting process works, so I guessed the issue link, it might be something else for this error, but my recommendation is to try that.
  • In filing a bug report you can link back to this post.
  • If you file a bug report post a link to it here either by editing this answer or posting a comment.
  • Related