0

So I added these maven dependencies in my project which will allow me to encode my logs in JSON. After doing this I reloaded maven on IntelliJ and I was able to run the Main class and use these dependencies:

<dependency>
    <groupId>net.logstash.logback</groupId>
    <artifactId>logstash-logback-encoder</artifactId>
    <version>7.2</version>
  </dependency>
  <dependency>
    <groupId>org.codehaus.janino</groupId>
    <artifactId>janino</artifactId>
    <version>2.6.1</version>
  </dependency>

When I do mvn clean install -DskipTests and run the exported jar then I get this error:

2023-01-11 13:07:54 13:07:54,863 |-ERROR in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Could not create component [encoder] of type [net.logstash.logback.encoder.LogstashEncoder] java.lang.ClassNotFoundException: net.logstash.logback.encoder.LogstashEncoder

Would someone know why the exported jar complains about not finding this dependency although when running the main class the dependency seems to be in use? Thanks in advance for the help

marialadelbario
  • 325
  • 1
  • 4
  • 19
  • IntelliJ knows about the dependencies, and can link to them. A separate JAR file has a pom.xml file, but the JVM doesn't use that - it's a Maven only thing. A JAR file's MANIFEST.MF may include references to its dependencies, but those need to be copied with the JAR. An alternative is to create a so-called _fat JAR_, that includes not just your code but also all dependencies. You can use the Maven shade plugin for that. – Rob Spoor Jan 11 '23 at 13:32
  • @RobSpoor hey thank you for your answer. would you maybe have links to examples? – marialadelbario Jan 11 '23 at 13:35
  • https://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html – Rob Spoor Jan 11 '23 at 13:40

0 Answers0