I have a standalone component which is Maven project that uses its own independent Log4j2. I want to package that complete project in a JAR file. When I run mvn clean build command, it creates a JAR file in the 'target' folder but when I use this jar in another Java project, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager
at com.company.client.model.ConnectionClient.<clinit>(ConnectionClient.java:24)
com.company.client.model.ConnectionClient.startXMLProcess(CallClient.java:25)
at com.company.client.model.ConnectionClient.main(CallClient.java:17)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.LogManager
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
But if I manually export that maven project to make an executable JAR and then use that JAR in another project, then it works absolutely fine.
So, I needed to know:
1) How can I generate a jar file for my component with the Log4j2 jars?
2) Am I right in assuming that I need to generate an executable JAR for my component so the generated JAR it can be used in other projects. If yes, then how can I do that in Maven.
Any help/advise will be appreciate.
Thanks