There are a few steps you need to take here. First, you should include the jcl-over-slf4j.jar
file, for example:
<!-- https://mvnrepository.com/artifact/org.slf4j/jcl-over-slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.28</version>
</dependency>
This JAR, if included at runtime, should receive all logging calls from anything using Jakarta commons logging, and then re-route it to your SLF4J facade (from which you may log with any implementation you want).
But, there is one additional step you should ideally take. You should change the dependency scope of commons-logging
to provided
in your Maven POM:
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>[1.0,)</version> <!-- include all possible versions -->
<scope>provided</scope> <!-- IMPORTANT -->
</dependency>
By making commons-logging
provided, you are telling Maven to include it during build time for any component in your code which needs it (e.g. something like Spring), but to exclude it at runtime, in the final JAR output. Instead, the bridge JAR jcl-over-slf4j.jar
mentioned above will be there at runtime. Spring, for example, will still be calling Jakarta logging at runtime, but that will really just be getting fed into the SLF4J facade, to end up with whatever logging implementation you provide.
Check the slf4j documentation which discusses a few of the things mentioned above.
Side note: You may want to run mvn dependency:tree
on your project to verify that your Maven library configuration be correct. You should not see any other logging implementation other than the one you chose to use with SLF4J. In particular, commons-logging
should only show up as provided
, i.e. it should not be on your classpath for your JAR.