Reputation: 8905
I am using log4j in android jar module. I can build the jar file successfully and run it in AndroidStudio successfully.
My gradle config is:
implementation 'log4j:log4j:1.2.17'
But when I try the jar file from command line:
java -jar test.jar
I got below error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at com.yeetor.Main.<clinit>(Main.java:39)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Why it can run in AndroidStudio but not work from command line?
Upvotes: 0
Views: 180
Reputation:
Refer to this SO, to generate one jar file include dependency. the dependency should be included using "compile" but not "implementation", then you will get a bigger Jar file include all dependency. Usually gradle will not include dependency in Jar file but generate all each dependency as a single jar file.
Upvotes: 0