即使libs在PATH和CLASSPATH中,NoClassDefFoundError也是如此

时间:2016-07-12 09:59:52

标签: java classpath

所需的jar(commons-codec和jsoup jar)都在PATH和CLASSPATH中,但仍然得到java.lang.NoClassDefFoundError。

有人可以帮忙吗?

    $ echo $PATH    
    /usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/aks/bin:/home/aks/f_group/lib/commons-codec-1.8.jar:/home/aks/f_group/lib/jsoup-1.9.2.jar

    $ echo $CLASSPATH
    /home/aks/focus_group/lib/commons-codec-1.8.jar:/home/aks/focus_group/lib/jsoup-1.9.2.jar


    $ java -cp ~/f_group/ExtractConfPages.jar com.ak.ExtractConfPages 
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64
    at com.ak.ExtractConfPages.main(ExtractConfPages.java:34)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64
    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

    $ java -jar ~/f_group/ExtractConfPages.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64
    at com.ak.ExtractConfPages.main(ExtractConfPages.java:34)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64
    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

2 个答案:

答案 0 :(得分:1)

保留ExtractConfPages.jar个文件和必需的jar(commons-codec和jsoup jar)  在同一目录中(例如在〜/ f_group /中)。 然后运行

java -cp ~/f_group/ExtractConfPages.jar com.ak.ExtractConfPages

答案 1 :(得分:0)

当我在类路径中包含所有jar时

java -classpath commons-codec-1.8.jar; jsoup-1.9.2.jar; ExtractConfluencePages.jar com.ak.ExtractConfluencePages