I am using log4j 2.3 in my java application. I added the dependency via maven.
When running the program in eclipse everything work fine, but when I package it with maven and try to run the jar I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache logging/log4j/LogManager
at main.myclass.<clinit>(myclass.java:11)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.LogManager
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
Why is it not able to find the class while running it from a jar?
Adding log4j 1.2
did not work either. The program is running fine in eclipse so there should be no missing dependency.
mvn dependency:tree
to find the culprit. Also, see #26338887 – Broochmvn dependency:tree
in eclipse? I have not installed maven for commandline use, just using it in eclipse. I have added log4j-cire(2.3) and log4j-api(2.3) as dependencys in my pom.xml. I run it from the commandline withjava -har myApplication.jar
– Edile