1

Before I ask the question here, I looked on internet. I found other questions with exactly the same titles, but I couldn't find the solution, or the solution proposed didn't work for me.

I am using Maven, with the following configuration:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.2.3</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>1.2.3</version>
    </dependency>

It compiles and works well when I run the application from the IDE (IntelliJ). However, when I create a jar file and try to run the main class, I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at dpsng.pgs.ValidationTool.<clinit>(ValidationTool.java:26)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory

I read several answers indicating to download jar files manually, I absolutely want to avoid this kind of solution.

What do I do wrong? Thanks!

Joel
  • 669
  • 7
  • 25
  • 1
    does your .jar contain denepencies? Sometimes the name might be `XXXApplication-with-dependencies.JAR` – Pijotrek Sep 18 '17 at 12:35
  • How do you create the jar? Which maven command do you use? – pleft Sep 18 '17 at 12:36
  • I use mvn package – Joel Sep 18 '17 at 12:36
  • 1
    Does your application JAR file contain the slf4j classes (aka an uber JAR) or does the classpath for your application include the slf4j JAR? – glytching Sep 18 '17 at 12:36
  • 1
    Open the jar file generated and look if it contains any dependencies, you are probably creating a jar of just your application classes and not a fat/uber jar. Look at https://stackoverflow.com/a/16222971/3635454 – pleft Sep 18 '17 at 12:38
  • Ok thanks, so I checked : yes I have only my classes. I installed the plugin referenced in the thread, version 3.1.0. I use mvn package but it seems I encounter a new error which is not related, due to resteasy dependency. I will fix this then try again. THANKS. – Joel Sep 18 '17 at 12:51
  • Can you show full pom.xml? Did you import project to IDE as Maven project? – Slava Medvediev Sep 18 '17 at 13:45
  • 1
    I used the maven plugin to include all dependencies and IT WORKS. THANKS. – Joel Sep 18 '17 at 13:50

0 Answers0