Imagine there is a jar (named lib.jar ) that contains a single class and manifest file.
The class is MyLibClass1. MyLibClass1 class contains single public static method execute().
The manifest file has a line "Class-Path:" that reference other jar files ( jar1.jar and jar2.jar )
MANIFEST.MF is in the META-INF of the lib.jar and contains:
Class-Path: jar1.jar jar2.jar
These jars are used in some project MyProject and are located in libs directory of it.
The project has a main class Main with method main and has only 1 line:
MyLibClass1.execute();
The problem is that when I try to invoke Main class of MyProject, JVM says that it is not able to find the MyLibClass1 class that is in the lib.jar .
java -cp libs/*;bin Main
Any suggestions?
UPDATE:
java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
The libs folder contains lib.jar , jar1.jar and jar2.jar
There is a good comment about where is Main.class. In fact the class in bin directory, so I have to change the java execution command.
java -cp libs/*;bin Main
如果当前目录是bin
,则应运行java -cp ".;../libs/*" Main
尝试在“ bin”之后添加分号。
java -cp libs/*;bin; Main
I have solved the problem by removing manifest from lib.jar file.
Therefore there is a bit confusing conclusion: "Class-Path:" of a jar hides the classes of a jar itself.
Welcome to disprove this statement.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.