如何正确设置Windows命令行中的类路径

时间:2015-06-14 21:55:34

标签: java windows command-line classnotfoundexception

我已经多次尝试输入命令从终端正确运行JAR文件,我100%确定所有JAR文件都在给定路径中,但我不断得到ClassDefNotFoundException。这与我输入命令的方式有关吗?

C:\Users\ANNA\Downloads>"C:\Program Files\Java\jre1.8.0_45\bin\java.exe" 

-Djava.library.path="C:\Users\ANNA\Downloads\Windows64_Libjitsi\lib\native\windows-64"

-cp 

"C:\Users\ANNA\Downloads\SimplifiedConnectionProvider.jar;C:\Users\ANNA\Downloads\Windows64_Libjitsi" 

Core.PublicService

Exception in thread "main" java.lang.NoClassDefFoundError: org/jitsi/service/lib
jitsi/LibJitsi
at Core.PublicService.<clinit>(PublicService.java:38)
Caused by: java.lang.ClassNotFoundException: org.jitsi.service.libjitsi.LibJitsi

    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 1 more

没有工作。再试一次:

C:\Users\ANNA\Downloads>"C:\Program Files\Java\jre1.8.0_45\bin\java.exe" -Djava.
library.path="C:\Users\ANNA\Downloads\Windows64_Libjitsi\lib\native\windows-64"
-cp C:\Users\ANNA\Downloads\SimplifiedConnectionProvider.jar;C:\Users\ANNA\Downl
oads\Windows64_Libjitsi Core.PublicService

Exception in thread "main" java.lang.NoClassDefFoundError: org/jitsi/service/lib
jitsi/LibJitsi
        at Core.PublicService.<clinit>(PublicService.java:38)
Caused by: java.lang.ClassNotFoundException: org.jitsi.service.libjitsi.LibJitsi

    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 1 more

没有工作。再试一次:

C:\Users\ANNA\Downloads>"C:\Program Files\Java\jre1.8.0_45\bin\java.exe" -Djava.
library.path=C:\Users\ANNA\Downloads\Windows64_Libjitsi\lib\native\windows-64 -c
p C:\Users\ANNA\Downloads\SimplifiedConnectionProvider.jar;C:\Users\ANNA\Downloa
ds\Windows64_Libjitsi Core.PublicService
Exception in thread "main" java.lang.NoClassDefFoundError: org/jitsi/service/lib
jitsi/LibJitsi
        at Core.PublicService.<clinit>(PublicService.java:38)
Caused by: java.lang.ClassNotFoundException: org.jitsi.service.libjitsi.LibJitsi

        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 1 more

注意班级&#34; org.jitsi.service.libjitsi.LibJitsi&#34;实际上是在一个JAR文件中,其真实位置位于文件夹&#34; C:\ Users \ Anna \ Downloads \ Windows64_Libjitsi&#34 ;,这是我试图在命令行上指定的JAR文件的类路径。

1 个答案:

答案 0 :(得分:1)

您已将JAR添加到 CLASSPATH ,而不是包含此JAR的文件夹。所以-cp参数应该是这样的C:\Users\ANNA\Downloads\SimplifiedConnectionProvider.jar;C:\Users\ANNA\Downloads\Windows64_Libjitsi\the_name_of_the_JAR.jar