my dog learned polymorphism
The moose likes Beginning Java and the fly likes How classpath works for executable Jars Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How classpath works for executable Jars" Watch "How classpath works for executable Jars" New topic

How classpath works for executable Jars

A Flatoff

Joined: Mar 22, 2005
Posts: 16
I've found that when I create a Java batch application and Jar it up as an executable jar (Main-class indicated in manifest, run with "java -jar")

That my external dependant Jar files are never found unless I add them to the class-path in the executable Jar's manifest file.

I always get ClassNoDefFound errors if I try to define the class in any of the following ways:

- System environment variable "CLASSPATH"
- java -classpath parameter

I am wondering if there is something special about executable JAR files where you are required to specify your classpath inside of the manifest only or what else might be going on here.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Yes. CLASSPATH environment variables and the -classpath switch are both ignored when Java is running an executable jar.

Moving to Java in General (Beginner).

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: How classpath works for executable Jars
jQuery in Action, 3rd edition