1
votes

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

3
make sure your lib.jar,jar1.jar and jar2.jar is inside WEB-INF/lib folder of your application - Vivek
What's the output of java -version? Where is the Main class, and which jars are in the libs folder? Note: if you don't use the -jar option, the classpath of the manifest is not taken into account. - JB Nizet
@Vivek: where have you seen that he has a webapp? He's trying to execute a main class, not to run a webapp. - JB Nizet
@JB Nizet...ohhh yes man...i thought so... - Vivek
Are you sure your imports are all correct? - Viruzzo

3 Answers

0
votes

If current dir is bin then you should run java -cp ".;../libs/*" Main

0
votes

Try to add a semicolon after "bin".

java -cp libs/*;bin; Main

0
votes

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.