I am trying to get a piece of code working with log4j. If I run it via junit tests (ant task), I am getting proper log outputs and all is fine. If I run the code from the command line, I get this:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Layout at uk.co.bytemark.flexnbd.Main.main(Main.java:29) Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Layout I tried the two following classpaths but neither helped. The error remains.
export CLASSPATH=/home/yann/java/apache-log4j-1.2.16/log4j-1.2.16.jar export CLASSPATH=/home/yann/java/apache-log4j-1.2.16/ Even with this
$ java -cp /home/yann/java/apache-log4j-1.2.16/log4j-1.2.16.jar -jar ./dist/lib/flexnbd-`date +%Y%m%d`.jar server ::1 12345 fileSystem Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Layout at uk.co.bytemark.flexnbd.Main.main(Main.java:29) Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Layout 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:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ... 1 more $ ls -ld /home/yann/java/apache-log4j-1.2.16/log4j-1.2.16.jar 476K -rw-r--r-- 1 yann yann 471K Mar 31 05:16 /home/yann/java/apache-log4j-1.2.16/log4j-1.2.16.jar Any idea what I am doing wrong?