I have jar file placed under C:\temp
inside jar Manifest file contains and all related jar files are there under lib folder
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
When I execute as
java -jar C:\temp\test.jar
I receive the error below:
A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
You're assuming that the Class-Path
refers to jar files within the jar file. It doesn't work that way. From "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.
So unpack the jar files to be alongside your main jar file.
See more on this question at Stackoverflow