2016-06-11 164 views
0

我使用這個命令來運行我的jar文件Jar文件執行問題?

java -cp otpreq.jar com.otp.req.SendRequest 

及其給無差錯:

Error: A JNI error has occurred, please check your installation and try again 
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/methods/RequestEntity 
    at java.lang.Class.getDeclaredMethods0(Native Method) 
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source) 
    at java.lang.Class.privateGetMethodRecursive(Unknown Source) 
    at java.lang.Class.getMethod0(Unknown Source) 
    at java.lang.Class.getMethod(Unknown Source) 
    at sun.launcher.LauncherHelper.validateMainClass(Unknown Source) 
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) 
Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.methods.RequestEntity 
    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) 
    ... 7 more 

爲什麼這個錯誤就要我想不通。

我檢查了庫和org/apache/commons/httpclient/methods/RequestEntity是一個接口。

回答

0

你必須在類路徑中包含所有支持的jar(命令行本身)。

或綁定otpreq.jar中的所有支持jar。

其中之一將解決此問題。

+0

我出口整個項目在Eclipse中JAR文件..這不是要所有的配套罐子綁定otpreq.jar – Mudit

+0

@Mudit內,默認情況下,如果源被導出,IDE將綁定所有的jar。請檢查這些東西 - 1)otpreq.jar中的.classpath文件。 2)檢查是否從外部路徑添加了庫3)嘗試在命令行中給出類路徑(-cp)中的所有庫。 – Bhuvanwaitz

1

假設你已經有HTTP-client.jar中:

java -cp otpreq.jar:http-client.jar com.otp.req.SendRequest 

如果O.S是窗戶,更換:通過;

注:最新的HttpClient不位於阿帕奇百科全書,但apache http components