Maven: module-info.java:[6,21] module not found: org.slf4j - maven

I'm currently migrating a project to Java 11 (i.e. >= 9) and because JavaFX seems not to work without modules, anymore, I'm currently adding module-info.java files to all sub-projects. But I get the following error:
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/mangu/workspace/cloudstore.2/co.codewizards.java9test.project1/src/main/java/module-info.java:[6,21] module not found: org.slf4j
[INFO] 1 error
I'm running OpenJDK 11.0.3, Maven 3.6.1 (embedded in Eclipse 2019-06) and I definitely have the dependency for the module org.slf4j declared in my pom.xml!
In order to simplify things, I created a little, minimal test-project causing the same error.
Here's the test-project's 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>co.codewizards.java9test</groupId>
<artifactId>co.codewizards.java9test.project1</artifactId>
<version>0.1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.8.0-beta4</version>
</dependency>
</dependencies>
</project>
I tried both: 1.8.0-beta4 and 2.0.0-alpha0. Eclipse shows me an existing module-info.class in both JARs (i.e. currently inside slf4j-api-1.8.0-beta4.jar).
Here's the module-info.java:
module co.codewizards.java9test.project1 {
requires java.base;
requires java.se;
requires org.slf4j;
}
And here's the output from mvn clean install -Dmaven.test.skip=true -X (but run inside Eclipse): mvn.log
Any idea what I'm doing wrong?
Update: I just uploaded the little test project: co.codewizards.java9test.project1.7z

Your maven logs show slf4j-api being placed on the classpath, not modulepath.
You need to upgrade the version of maven-compiler-plugin, as modulepath is supported only since version 3.6, whereas your build uses version 3.1.

I was getting the same issue due to older verion of slf4j was coming from one of dependency in pom. So I resolved it by adding below slf4j dependency to my pom :
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.29</version>
</dependency>
module-info:
module my.service {
requires org.slf4j;
}

Related

Liquibase fails with MongoDB

I want to get an example of liquibase, Spring and MongoDB all together. In order to do so, I created a Spring project using Spring Initializr with Spring Data MongoDB as dependency. The project already connects to the database and now I would like to use liquibase. I followed the instructions from liquibase using the maven approach but if I run the maven command mvn liquibase:status I will get the following error:
Unexpected error running Liquibase: Cannot find database driver: com.mongodb.client.MongoClients.<init>()
It looks like this problem has been already reported to liquibase but if there is a solution it hasn't been posted in the issue.
I tried as well to use the CLI option by adding the jars to the lib folder of the liquibase installation. I got the same error if I run liquibase status
I have created a repo in GitHub to show the problem. Here there is some relevant configuration of the code:
pom.xml
<project>
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
...
<properties>
<liquibase-mongo-ext.version>4.14.0</liquibase-mongo-ext.version>
<liquibase-maven-plugin.version>4.2.0</liquibase-maven-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-mongodb</artifactId>
<version>${liquibase-mongo-ext.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase-maven-plugin.version}</version>
<configuration>
<propertyFile>liquibase.properties</propertyFile>
</configuration>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-mongodb</artifactId>
<version>${liquibase-mongo-ext.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.6.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
liquibase.properties
changeLogFile=./mongo/changelog/changelog.sql
url=jdbc:mongodb://127.0.0.1:27017/local
driver=com.mongodb.client.MongoClients
How can I get liquibase running with maven? Any suggestions?
EDIT 1:
As Andrey suggested:
Driver was updated to: driver=liquibase.ext.mongodb.database.MongoClientDriver
Url was updated to:
url=mongodb://127.0.0.1:27017/local
plugin from liquibase was updated with new dependency
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.9.1</version>
</dependency>
mvn liquibase:update now trhows the following error. Since the other error seems to be unrelated to this one. I'll solve this answer and create a new thread.
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:4.2.0:update (default-cli) on project mongo: Execution default-cli of goal org.liquibase:liquibase-maven-plugin:4.2.0:update failed: A required class was missing while executing org.liquibase:liquibase-maven-plugin:4.2.0:update: liquibase/configuration/HubConfiguration
EDIT 2:
As mentioned in the answer, there was a mismatch between the version from Spring and the version of the plugin, which failed to find the class because HubConfiguration class is now under liquibase.hub.HubConfiguration This set up could have led to a CastException as well. So I updated the version liquibase-maven-plugin to 4.9.1
Also the use of the local database is not compatible with validators. The URI was updated to url=mongodb://127.0.0.1:27017/test in the liquibase.properties file.
Now it works like a charm! :D
I have found following mistakes in your configuration:
1.
changeLogFile=./mongo/changelog/changelog.sql
url=jdbc:mongodb://127.0.0.1:27017/local
driver=com.mongodb.client.MongoClients
while liquibase-mongodb expects something like (no jdbc prefix, another driver class):
changeLogFile=./mongo/changelog/changelog.sql
url=mongodb://127.0.0.1:27017/local
driver=liquibase.ext.mongodb.database.MongoClientDriver
liquibase version:
<liquibase-maven-plugin.version>4.2.0</liquibase-maven-plugin.version>
4.2.0 liquibase version seems to be incompatible with NoSQL DB extensions
spring boot 2.7.3 uses liquibase 4.9.1 - you need somehow choose the correct liquibase version
Finally I get the following on liquibase:update:
[ERROR] Failed to execute goal
org.liquibase:liquibase-maven-plugin:4.14.0:update (default-cli) on
project mongo: [ERROR] Error setting up or running Liquibase: [ERROR]
liquibase.exception.DatabaseException: Could not execute: Command
failed with error 72 (InvalidOptions): 'Document validators are not
allowed on collection local.DATABASECHANGELOGLOCK with UUID
31bd40b8-3e1c-45c8-9d03-77b91c67a1a9 in the local internal database'
on server 127.0.0.1:27017. The full response is {"ok": 0.0, "errmsg":
"Document validators are not allowed on collection
local.DATABASECHANGELOGLOCK with UUID
31bd40b8-3e1c-45c8-9d03-77b91c67a1a9 in the local internal database",
"code": 72, "codeName": "InvalidOptions"}
no idea what does it mean - something related to mongodb and extension I believe
UPD.
The root cause of last error is described in documentation:
Restrictions
You cannot specify a validator for collections in the admin, local, and config databases.
You cannot specify a validator for system.* collections.
So, url (jdbc:mongodb://127.0.0.1:27017/local) should point to another db.

Mulesoft Maven configuration error. Can't depoloy to Cloudhub from terminal

I am trying to deploy my mule project from Anypoint using terminal "mvn clean package deploy-DmuleDeploy" command. I am not sure what this error is saying but i'm sure it has to do with my maven version. I've installed maven on my mac using homebrew, but it is version 3.8.6. The "embedded maven installation" under preferences-AnypointStudio-maven in Anypoint says 3.6.3. Then the plugin version on my .pom file says 3.5.4. Do i need to change any of these versions? Should i edit the one in the .pom file? Should i downgrade my mac maven version? Any help would be appreciated. I've posted a partial error and a partial .pom file. Please let me know if you need any more info to help me. Thank you
> [ERROR] Failed to execute goal org.mule.tools.maven:mule-maven-plugin:3.5.4:process-sources (default-process-sources) on project maven: Execution default-process-sources of goal org.mule.tools.maven:mule-maven-plugin:3.5.4:process-sources failed: An API incompatibility was encountered while executing org.mule.tools.maven:mule-maven-plugin:3.5.4:process-sources: java.lang.IllegalAccessError: class org.mule.maven.client.internal.util.FileUtils (in unnamed module #0x6d9fb2d1) cannot access class sun.net.www.protocol.jar.JarURLConnection (in module java.base) because module java.base does not export sun.net.www.protocol.jar to unnamed module #0x6d9fb2d1
[ERROR] -----------------------------------------------------
[ERROR] realm = extension>org.mule.tools.maven:mule-maven-plugin:3.5.4
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/Users/ammanbesaw/.m2/repository/org/mule/tools/maven/mule-maven-plugin/3.5.4/mule-maven-plugin-3.5.4.jar
Pom file
> <?xml version="1.0" encoding="UTF-8"?>
<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.mycompany</groupId>
<artifactId>maven</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>mule-application</packaging>
<name>maven</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<app.runtime>4.4.0-20220523</app.runtime>
<mule.maven.plugin.version>3.5.4</mule.maven.plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>3.5.4</version>
<extensions>true</extensions>
The cause of the error seems to be that Maven is using a Java/JDK version that is not supported by Mule. Only Java/JDK versions 8 and 11 are supported. Ensure that Maven is executing a supported JDK version.
While making a build for your project in any cloud environment. Try to change image from linux/unix to window or window to other. Operating system and image should be the same to successfully build.

Selenium-TestNG-Maven - Getting "java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver"

This is my first selenium script using TestNG and Maven.
Created a simple "Hello World" code and a selenium test code which just checks the title of google page.
Selenium Code Below with TestNG:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class HelloTest {
#Test
public void testOne() {
//WebDriver d=new FirefoxDriver();
System.setProperty("webdriver.gecko.driver","D:\\Firefox Driver\\geckodriver-v0.17.0-win64\\geckodriver.exe");
WebDriver d=new FirefoxDriver();
d.get("https://www.google.com");
System.out.println("This is first TestNG");
}
}
This is working absolutely fine when run through eclipse - Run As - Test NG test.
But when ran through Maven - mvn clean install from cmd prompt, i am getting below error
T E S T S
-------------------------------------------------------
Running HelloTest
Configuring TestNG with: TestNG652Configurator
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.94 sec <<< FAILURE! - in HelloTest
testOne(HelloTest) Time elapsed: 0.032 sec <<< FAILURE!
java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at HelloTest.testOne(HelloTest.java:11)
It is showing error at WebDriver d=new FirefoxDriver();. Not sure where the issue is. Added all jar files , checked the build path and all the jar were there. Below is my POM file.
<?xml version="1.0"?>
<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.demo.micky</groupId>
<artifactId>MavenDemoTwo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
<type>jar</type>
<version>15.0</version>
</dependency>
</dependencies>
</project>
Any help is deeply appreciated.
What is NoClassDefFoundError
NoClassDefFoundError in Java occurs when JVM is not able to find a particular class at runtime which was available at compile time. For example, if we have resolved a method call from a Class or accessing any static member of a Class and that Class is not available during runtime then JVM will throw NoClassDefFoundError.
The error you are seeing is :
java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver
This clearly indicates that Selenium is trying to resolve the particular FirefoxDriver Class at runtime from org/openqa/selenium/firefox/FirefoxDriver which is not available.
What went wrong :
This situation occurs if there are presence of multiple sources to resolve the Classes and Methods through JDK/Maven/Gradle.
From the pom.xml it is pretty clear that you have added multiple dependencies for FirefoxDriver Class as follows:
<artifactId>selenium-java</artifactId>:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.12.0</version>
<scope>test</scope>
</dependency>
<artifactId>selenium-firefox-driver</artifactId>:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.12.0</version>
</dependency>
<artifactId>selenium-server</artifactId>:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.12.0</version>
</dependency>
Additionally you have also added all jar files.
From all the above mentioned points it's clear that the related Class or Methods were resolved from one source at Compile Time which was not available during Run Time.
Solution :
Here are a few steps to solve NoClassDefFoundError :
While using a Build Tool e.g. Maven or Gradle, remove all the External JARs from the Java Build Path. Maven or Gradle will download all the dependencies mentioned in the configuration file (e.g. pom.xml) to resolve the Classes and Methods.
If using Selenium JARs within a Java Project add only required External JARs within the Java Build Path and remove the unused and duplicate External JARs.
If you are using FirefoxDriver use either of the <artifactId>selenium-java</artifactId> or <artifactId>selenium-server</artifactId>. Avoid using both at the same time.
Remove the unwanted and duplicated from pom.xml
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Take a System Reboot.
While you execute a Maven Project always perform the folling in sequence:
maven clean
maven install
maven test
You can find related discussions in:
Exception in thread “main” java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
How to solve java.lang.NoClassDefFoundError? Selenium
java.lang.NoClassDefFoundError: com/google/common/base/Function
I was using eclipse 09-2019 which is the latest one with latest JDK installed 13, and latest selenium jar files 3.141.59, I installed other JDKs to work around to solve this issue after trying all answers on similar question. Then after 4 days trying, installed eclipse neon version(https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/neon/3/eclipse-java-neon-3-win32-x86_64.zip&mirror_id=105) and used Selenium-Java 3.5.2 jar files (https://jar-download.com/artifacts/org.seleniumhq.selenium/selenium-java/3.5.2/source-code) and now it is working perfectly Alhamdullilah.
Also I don't know what was the errors root cause exactly or at all, but now it is solved.
Wish if that help You

Not able to run RichFaces, getting different kind of exceptions

I have developed a sample JSF application and it is running fine but I am having hardtime to run RichFaces example in JSF.
My runtime environment details: Weblogic 12.1.2, JEE 6 and JSF 2.0.
I downloaded below JARs and placed then in my WEB-INF/lib but it doesn't work.
richfaces-4.5.0.Final.jar
richfaces-a4j-4.5.0.Final.jar
richfaces-core-4.5.0.Final.jar
With these JARs, when I started my server I got class not found exception related to AtmosphereServlet so I included atmosphere-runtime-1.0.2.jar JAR and then I was getting java.lang.ClassNotFoundException: org.reflections.scanners.AbstractScanner exception.
org.reflections.scanners.AbstractScanner was not from a very popular JAR and only JAR I found for this was here. Even though I was not convinced that I should use this but still to try out I added this and then I was getting java.lang.ClassNotFoundException: org.apache.catalina.CometProcessor.
To resolve this I added this JAR. Now, I am getting java.lang.ClassNotFoundException: org.jboss.servlet.http.HttpEventServlet exception.
I am totally convinced that I am not heading in right direction because like this I may end up adding Tomcat and Jboss/Wildfly JARs in my classpath.
I searched blogs there is no clear post saying that with these JARs RichFaces works, whatever JARs were mentioned in the post I added all, at this moment I have following JARs but still have the same exception:
atmosphere-runtime-1.0.2.jar
commons-beanutils-1.8.0.jar
commons-logging-1.0.4.jar
guava-19.0.jar
richfaces-4.5.0.Final.jar
richfaces-core-4.5.0.Final.jar
catalina-comet.jar
commons-collections-3.2.jar
cssparser-0.9.18.jar
reflections-0.9.6_jboss_errai_r2.jar
richfaces-a4j-4.5.0.Final.jar
sac-1.3.jar
Another problem I am facing is that I don't know Maven so I am not able to resolve the dependencies using it, I tried below pom.xml but nothing works, it doesn't download any JAR, it simply builds some almost useless JAR.
<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>org.jvi.weblogic.jms</groupId>
<artifactId>jms-producer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>jms-producer</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-bom</artifactId>
<version>4.2.2.Final</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
<!--version>4.2.2.Final</version-->
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
<!--version>4.2.2.Final</version-->
</dependency>
</dependencies>
</dependencyManagement>
</project>
Could someone please guide and help me to run RichFaces in my JSF application.
P.S.: I am able to run PrimeFaces but RichFaces dependencies looks very bad.
UPDATE 1: I also followed the official documentation and downloaded the distribution from here and had below mentioned JARs but still no help.
cssparser-0.9.18.jar
guava-19.0.jar
richfaces-a4j-4.5.17.Final.jar
richfaces-core-4.5.17.Final.jar
richfaces-page-fragments-4.5.17.Final.jar
richfaces-rich-4.5.17.Final.jar sac-1.3.jar
I had got it working. Below are the RichFaces JARs which would work with JEE 6 container and JSF 2.0; this is tested and RichFaces works with these JARs in WEB-INF/lib
richfaces-components-api-4.0.0.Final.jar
richfaces-core-api-4.0.0.Final.jar
richfaces-components-ui-4.0.0.Final.jar
richfaces-core-impl-4.0.0.Final.jar
cssparser-0.9.18.jar
sac-1.3.jar
Last 2 JARs are the dependencies.

Hbase 0.98.0-hadoop2 mvn dependency

I am adding hbase jars in my client project using mvn dependency
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase</artifactId>
<version>0.98.0-hadoop2</version>
</dependency>
However, mvn is not able to find the required version and is giving error. I myself checked at following link but there is no hbase-0.98.0-hadoop2.jar present at that location. Please help
Downloading: http://repo1.maven.org/maven2/org/apache/hbase/hbase/0.98.0-hadoop2/hbase-0.98.0-hadoop2.jar
[INFO] Unable to find resource 'org.apache.hbase:hbase:jar:0.98.0-hadoop2' in repository java.net (http://repo1.maven.org/maven2)
Downloading: https://repository.jboss.org/maven2//org/apache/hbase/hbase/0.98.0-hadoop2/hbase-0.98.0-hadoop2.jar
[INFO] Unable to find resource 'org.apache.hbase:hbase:jar:0.98.0-hadoop2' in repository jboss (https://repository.jboss.org/maven2/)
Thanks in advance.
Dependency definition which you have mentioned has been updated. Use below maven dependency definition instead :-
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>0.98.8-hadoop2</version>
</dependency>
this will solve your problem.

Resources