Re: NoClassDefFoundError is driving me insane!

On Friday 06 July 2007, Sheppard, Eric wrote:
> I would very much like to get the CSS Validator working on my local
> machine command line but Java is ignoring all class paths! Java is JDK
> 1.5.0_10 on a Unix host.
>
> # cd {dir containing jars}
> # export
> CLASSPATH=css-validator.jar:jigsaw.jar:servlet-api.jar:tagsoup-1.1.3.jar
>
> :xercesImpl.jar:xml-apis.jar
>
> # java -jar css-validator.jar
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/w3c/tools/resources/ProtocolException

From "man java":

    -jar
        Execute a program encapsulated in a JAR file. [...]
        When you use this option, the JAR file is the source of all user
        classes, and other user class path settings are ignored.

In other words, an app that is supposed to be run like "java -jar ..." needs 
to be self-contained in the jar or the classpath set in the Class-Path 
attribute of the jar's META-INF/MANIFEST.MF, and obviously things specified 
in the manifest Class-Path found where expected.  Running the main class the 
usual way by its name (without "-jar") does not have this limitation.

Received on Saturday, 7 July 2007 20:13:25 UTC