0

Hi, i use Intellij since 5 days, and it looks pretty good. So i created a new java project and use log4j2, easy business, everything works fine. Then i created an artifact for easy deployment. The problem, i'am not able to run / execute the artifact JAR file! I get the error, taht the log4j.xml is missing:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager
        at iBox.IBox.<init>(IBox.java:64)
        at iboxapp.Start.main(Start.java:28)
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)

Log4j.xml is part of the artifact (JAR file). Where is the correct location for the xml file?! I don't use Maven, Intellij 2017.2

Any ideas?!

Thx

Sascha
  • 31
  • 4
  • It's a dependencies problem, you don't use maven what do you use? – Yamen Nassif Aug 29 '17 at 07:38
  • I just use IntelliJ, add the dependencies and build the artifact by hand. I don't know whats running in the background as default. – Sascha Aug 29 '17 at 07:40
  • Possible duplicate of [unexpected exception: java.lang.NoClassDefFoundError: org/apache/log4j/LogManager](https://stackoverflow.com/questions/26338387/unexpected-exception-java-lang-noclassdeffounderror-org-apache-log4j-logmanage) – Meo Aug 29 '17 at 08:07
  • I'll check it, thx – Sascha Aug 29 '17 at 08:13

2 Answers2

1

The problem was a mix of old and new log4j references. After cleanup, everything works fine. THX

Sascha
  • 31
  • 4
0

First of all you should use a proper build system instead of relying on the IDE. I recommend gradle if you start from scratch.

Now that this is said: The error does not complain about missing xml file, but about missing class file.

How did you create the artifact? For testing I just

  • created a Java project in IDEA
  • added library dependencies to log4j-api and log4j-core, version 2.8.2
  • added a main class that just logs a single line using log4j
  • added an log4j2.xml to the root of the "src" folder
  • created an artifact:
    • Project Settings -> Artifacts -> "+" -> Jar -> from modules with dependencies
    • selected the main class
    • and kept the "JAR files from libraries" -> extract to the target JAR" selected
  • build the artifact: Build -> Build Artifacts
  • executed the artifact from the out/artifacts/test-artifact folder using "java -jar test-artifact"

Works without problems.

eekboom
  • 5,551
  • 1
  • 30
  • 39