Take the 2-minute tour ×

Okay, so I've got the following file tree:

- MyApp.jar
- lib/
-    log.jar
-    someother.jar
-    someother.jar
-    someother2.jar
- config.properties
- otherfiles.extension

I've tried dozens of way to launch this application. MyApp contains the following

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.7.0_06-b24 (Oracle Corporation)
Main-Class: myapp.Main
Class-Path: MyApp.jar lib/*

If I invoke java -jar MyApp.jar it always says none of the classes in lib/log.jar could be loaded.

Here is a part of the combinations I've tried:

- *.jar lib/*
- *.jar lib/*.jar
- *.jar ./lib/*.jar
- ./*.jar lib/*.jar
- *.jar ./lib/*.jar
- tbc

NOTHING worked. Java always tells me that it could not find the classes inside the lib/log.jar

My next attempt was to specify the classpath via the command line.

java -cp "MyApp.jar:lib/*" myapp.Main

But even that doesn't work. In this case Java says it could not find the myapp.Main class.

I guess I'm doing something completely wrong since nothing of the methods I've found worked. If I put the classes from lib/log.jar into myApp.jar and start it it'll work. But that can't be the solution.

Any ideas?

Edit: I don't want to name every single lib jar. I just want the ClassLoader to search the ClassPath for the needed classes. I've seen this so many times.

share|improve this question
I am not sure but I think you cannot use wildcards inside the manifest file. It will work for sure if you literally list all the jars like Class-Path: lib/a.jar lib/b.jar. As another combination can you please try Class-Path: lib/** (note the 2 stars is NOT a typo) –  Ankit Aug 29 '12 at 16:31

2 Answers 2

For Linux, you should be able to do something like this:

java -cp MyApp.jar:lib:someotherjar.jar myapp.Main

You can (optionally!) use "-jar" for a .jar that contains your "main", or you can add any combination of paths and jar files (.jar file with qualified path names) to your classpath.

Here's the Java documentation

And here's a somewhat better explanation

share|improve this answer

add lib directory to your classpath via system variables , or via


and then do a java -jar MyApp.jar

share|improve this answer
The problem is the classpath construction, it doesn't matter if it's in an environment variable or the java command itself. –  Dave Newton Aug 26 '12 at 23:41

Your Answer


