Could not find the main class. Program will exit.

From: thufir (thufir.hawat_at_mail.com)
Date: 01/26/05


Date: 26 Jan 2005 00:26:01 -0800

The jar which ant creates appears to be flawed in some respect. The
jar isn't executable by double-clicking, nor by the command line.
However, the manifest, directory structure and source code appear ok to
me. The source code is from Sun, I've only added "package
atreides.java;" to the first line. How do I narrow down the error,
please?

////////////////command line//////////////////////

C:\>
C:\>ant
Buildfile: build.xml

clean:
[delete] Deleting directory C:\java\classes

prepare:
[mkdir] Created dir: C:\java\classes

compile:
[javac] Compiling 1 source file to C:\java\classes

manifest:

package:
[jar] Building jar: C:\java\classes\HelloWorldSwing.jar

BUILD SUCCESSFUL
Total time: 4 seconds
C:\>cd java\classes\atreides\hello

C:\java\classes\atreides\hello>dir
Volume in drive C has no label.
Volume Serial Number is #####

Directory of C:\java\classes\atreides\hello

01/26/2005 12:08a <DIR> .
01/26/2005 12:08a <DIR> ..
01/26/2005 12:08a 367 HelloWorldSwing$1.class
01/26/2005 12:08a 915 HelloWorldSwing.class
2 File(s) 1,282 bytes
2 Dir(s) 4,166,443,008 bytes free

C:\java\classes\atreides\hello>java -classpath .;C:\java\classes\
atreides.hello.HelloWorldSwing

C:\java\classes\atreides\hello>cd ..

C:\java\classes\atreides>cd ..

C:\java\classes>dir
Volume in drive C has no label.
Volume Serial Number is #####

Directory of C:\java\classes

01/26/2005 12:08a <DIR> .
01/26/2005 12:08a <DIR> ..
01/26/2005 12:08a <DIR> atreides
01/26/2005 12:08a 1,906 HelloWorldSwing.jar
01/26/2005 12:08a 135 MANIFEST.MF
2 File(s) 2,041 bytes
3 Dir(s) 4,166,443,008 bytes free

C:\java\classes>java -jar HelloWorldSwing.jar
Exception in thread "main" java.lang.NoClassDefFoundError:
HelloWorldSwing

C:\java\classes>jar -tvf HelloWorldSwing.jar
0 Wed Jan 26 00:08:58 PST 2005 META-INF/
135 Wed Jan 26 00:08:56 PST 2005 META-INF/MANIFEST.MF
135 Wed Jan 26 00:08:58 PST 2005 MANIFEST.MF
0 Wed Jan 26 00:08:58 PST 2005 atreides/
0 Wed Jan 26 00:08:58 PST 2005 atreides/hello/
367 Wed Jan 26 00:08:58 PST 2005
atreides/hello/HelloWorldSwing$1.class
915 Wed Jan 26 00:08:58 PST 2005
atreides/hello/HelloWorldSwing.class

C:\java\classes>
C:\java\classes>
C:\java\classes>type MANIFEST.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.5.0_01-b08 (Sun Microsystems Inc.)
Main-Class: HelloWorldSwing

C:\java\classes>
C:\java\classes>cd c:\

C:\>type build.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="HelloWorldBuild" default="package">

<property name="outputDir" value="C:\java\classes\" />
<property name="sourceDir"
value="C:\java\sources\atreides\hello\" />
<property name="mainClass" value="HelloWorldSwing" />

<target name="clean">
<delete dir="${outputDir}" />
</target>

<target name="prepare" depends="clean">
<mkdir dir="${outputDir}" />
</target>

<target name="compile" depends="prepare">
<javac srcdir="${sourceDir}" destdir="${outputDir}" />
</target>

<target name="manifest" depends="compile">
<manifest file="${outputDir}/MANIFEST.MF">
<attribute name="Main-Class"
value="${mainClass}" />
</manifest>
</target>

<target name="package" depends="manifest">
<jar jarfile="${outputDir}/${mainClass}.jar"
basedir="${outputDir}"
manifest="${outputDir}/MANIFEST.MF" />
</target>

</project>

C:\>
C:\>cd java\classes

C:\java\classes>dir
Volume in drive C has no label.
Volume Serial Number is #####

Directory of C:\java\classes

01/26/2005 12:08a <DIR> .
01/26/2005 12:08a <DIR> ..
01/26/2005 12:08a <DIR> atreides
01/26/2005 12:08a 1,906 HelloWorldSwing.jar
01/26/2005 12:08a 135 MANIFEST.MF
2 File(s) 2,041 bytes
3 Dir(s) 4,166,410,240 bytes free

C:\java\classes>java -jar HelloWorldSwing.jar
Exception in thread "main" java.lang.NoClassDefFoundError:
HelloWorldSwing

C:\java\classes>

thanks,

Thufir Hawat