2016-12-16 134 views
0

我已經jar文件放置在C:\ TEMP爲什麼從CMD運行JAR文件時收到NoClassDefFoundError?

內JAR清單文件包含所有相關的jar文件有lib文件夾

Manifest-Version: 1.0 
Ant-Version: Apache Ant 1.9.1 
Created-By: 1.8.0_111-b14 (Oracle Corporation) 
Class-Path: lib/httpclient-4.2.1.jar lib/httpcore-4.2.1.jar lib/common s-logging-1.1.1.jar lib/httpclient-cache-4.2.5.jar lib/httpmime-4.2.5.jar lib/log4j-1.2.13.jar lib/log4j-api-2.0-beta9.jar lib/log4j-core-2.0-beta9.jar lib/gson-2.2.4-javadoc.jar lib/gson-2.2.4-sources.jar lib/gson-2.2.4.jar 
X-COMMENT: Main-Class will be added automatically by build 
Main-Class: abc.service.Main 

當我執行的

java -jar C:\temp\test.jar 

我下收到以下錯誤:

A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient

+1

你的意思是你的'lib'目錄*在jar文件裏面?我不認爲*會有所幫助。嘗試將lib目錄與jar文件直接放在'c:\ temp'中,然後再試一次... –

+0

是的。所有依賴jar文件都在test.jar的lib裏面 – user3312405

+0

就我所知,jar文件清單的'Class-Path'屬性不能像那樣工作。 –

回答

1

你在假設Class-Path是指jar文件內的jar文件。它不這樣工作。從"Adding classes to the JAR file's classpath"

Note: The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over Internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.

所以解壓的jar文件是沿着你的主jar文件。

相關問題