Unwanted output related to SLF4J
wilyJ80 opened this issue · 1 comments
Description, Reproducing, Expected behavior, Logs, following:
(Sorry for the long text, I just want to document this for people who might have the same problem, also, I'm a beginner in the way of the Maven, so have patience 😭)
I'm making a simple SQLite CLI app. All I wanted was to bundle the whole SQLite app into a fat jar using Maven, so this should be simple, right? Right?
Since I wanted to use Maven, I avoided manually downloading the jars, as instructed by the README, and tried to add the Maven plugin for sqlite-jdbc, of course, as well as the other Maven configurations described (the hint for maven-shade-plugin). There's nothing special in the following pom.xml
, it's just the default Maven archetype with the necessary adjustments I wanted.
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sqlite</groupId>
<artifactId>sqlite</artifactId>
<version>1.0-SNAPSHOT</version>
<name>sqlite</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.45.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>sqlite.App</mainClass>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/java.sql.Driver</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to
parent pom) -->
<plugins>
<!-- clean lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see
https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
- Trying to run it after creating the fat jar with
mvn clean package
:
[victor@victor-82mf sqlite]$ java -jar target/sqlite-1.0-SNAPSHOT.jar
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Connection to SQLite has been established.
- Well, this seems to work OK, since the point of the app is simply to test the connection. But I sure as heck don't want that unwanted warnings in my CLI app output, sorry. So let's try something else: the logical next step is adding the
sl4j-api
dependency to my pom.xml. I hope it works... and yes, I read the issue where it's described the version of slf4j is an older version, so I made the following adjustment with that in mind:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
- Same unwanted logging:
[victor@victor-82mf sqlite]$ java -jar target/sqlite-1.0-SNAPSHOT.jar
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Connection to SQLite has been established.
- Some digging on StackOverflow instructed adding the slf4j-nop plugin to my pom. Let's be careful and add the same version as the slf4j-api plugin. Well, here we go:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.36</version>
<scope>test</scope>
</dependency>
-
Same errors.
-
What to do? Thank you for any help, by the way.
Environment (please complete the following information):
- OS: EndeavourOS
- CPU architecture: x86_64
- sqlite-jdbc version 3.45.3.0
you need to include an implementation of slf4j like slf4j-simple or logback