Using maven-shade-plugin with SLF4J and logback to build a fat jar

1,587 views
Skip to first unread message

Nick P

unread,
Nov 23, 2016, 4:31:01 PM11/23/16
to vert.x
Hi

I want to use the maven-shade-plugin to create a fat jar to use in something like
vertx run com.x.y.Z -cp fat.jar

This works, however, SLF4J does not find the included StaticLoggerBinder from Logback.
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.

This seems somewhat of a known issue since:

But I could not find a simple solution to add my logging jars in a way, SLF4J can find them.

Please advice.

Best regards
Nick

Julien Viet

unread,
Nov 24, 2016, 12:08:28 AM11/24/16
to ve...@googlegroups.com
have you tried in vertx/lib directory ?

-- 
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/c65db843-e386-4ebe-89f1-11014c7c73d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alexander Lehmann

unread,
Nov 24, 2016, 6:45:19 AM11/24/16
to vert.x
The issue is for vertx 2.x, that is not applicable to vertx 3.x.

How are you building your fatjar?

Nick P

unread,
Nov 24, 2016, 7:32:57 AM11/24/16
to vert.x
No yet.. Will do so and post again

Nick P

unread,
Nov 24, 2016, 7:33:47 AM11/24/16
to vert.x
Using the maven-shade-plugin as follows:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet/>
                            <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Alexander Lehmann

unread,
Nov 25, 2016, 6:24:59 AM11/25/16
to vert.x
That looks ok, it would be interesting to check if the class file is included in the final jar

Nick P

unread,
Nov 25, 2016, 10:44:43 AM11/25/16
to vert.x
I pushed a small git repo to reproduce the issue:
See the README.md for instructions...

The outputs of jar tf indicate, that the logging class files are in fact included in the final jar...

jar tf demo-0.0.1-SNAPSHOT-fat.jar | grep StaticLoggerBinder
org/slf4j/impl/StaticLoggerBinder.class

Thanks for your help guys!

Alexander Lehmann

unread,
Nov 25, 2016, 6:48:16 PM11/25/16
to vert.x
That doesn't work because the logging code is not in the classpath when logging is initialized in the netty initializer code. The fatjar is put into the classpath in the starter code of vertx when parsing the command parameters but at that point the logging is already loaded (or has failed to load).

There are two possibilities how you can make that work, either put logback-core.jar and logback-classic.jar into the vertx/lib directory along with the slf4j-api.jar, this way the logging can be initialized in the vertx starter without needing the fatjar.

Or you could configure the starter verticle for the fatjar and run the jar without using the vertx command with java -jar fatjar.jar, this way all classes are in the classpath at startup and the logging will work.
Reply all
Reply to author
Forward
0 new messages