I am trying simple Maven app with Log4J ver 2-beta 9. In my pom.xml file I have these two dependencies (as is mentioned in Log4J Maven webpage):
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0-beta9</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0-beta9</version>
</dependency>
Eclipse sees Log4J library:
But when I package the app and run it this Exception is thrown:
java -cp target/notification-1.0.0.jar com.example.Sandbox
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/LogManager
at com.example.Sandbox.<clinit>(Sandbox.java:13)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.LogManager
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 1 more
I searched for this Exception and it seems to be related to CLASSPATH variable.
How should be CLASSPATH set for Maven project?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…