There are two .java files as follows:
File Tmdl.java
========================
package testpkgjar;
public class Tmdl {
Tmdl() {
}
}
========================
File Tvc.java
========================
package testpkgjar;
public class Tvc {
Tmdl mdl = new Tmdl();
public Tvc() {
}
public static void main( String[] args ) {
new Tvc();
}
}
========================
File MyMainClass
========================
Main-Class: Tvc
========================
compile these with:
c:\jdk1.2\bin\javac Tvc.java Tmdl.java
Make the jar file with:
c:\jdk1.2\bin\jar cfm Mvc.jar MyMainClass Tvc.class Tmdl.class
Whereupon the jar file, when listed with:
c:\jdk1.2\bin\jar tvf Mvc.jar looks like:
========================
0 Tue Dec 29 15:03:54 GMT 1998 META-INF/
83 Tue Dec 29 15:03:54 GMT 1998 META-INF/MANIFEST.MF
366 Tue Dec 29 15:00:52 GMT 1998 Tvc.class
193 Tue Dec 29 15:00:52 GMT 1998 Tmdl.class
========================
Its META-INF/MANIFEST.MF looks like:
========================
Manifest-Version: 1.0
Main-Class: Tvc
Created-By: 1.2 (Sun Microsystems Inc.)
========================
Execute this with:
c:\jdk1.2\bin\java -jar Mvc.jar
The execution output then looks like:
========================
Exception in thread "main" java.lang.NoClassDefFoundError: Tvc (wrong
name: testpkgjar/Tvc)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:403)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:101)
at
java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$1(URLClassLoader.java:216)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:191)
at java.lang.ClassLoader.loadClass(ClassLoader.java:280)
at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:275)
at java.lang.ClassLoader.loadClass(ClassLoader.java:237)
========================
Any ideas as to why this result?
Thanks
Kurt Berg
Kurt Berg wrote:
> File Tvc.java
> ========================
> package testpkgjar;
...
> 366 Tue Dec 29 15:00:52 GMT 1998 Tvc.class
> 193 Tue Dec 29 15:00:52 GMT 1998 Tmdl.class
^^^^^^^^^^
should be testpkgjar.Tmdl.class ?
go to the directory that contains testpkgjar, c:\jsrc\, and run
c:\jdk1.2\bin\jar cfm Mvc.jar MyMainClass testpkgjar.Tvc.class
testpkgjar.Tmdl.class
""""""""""
""""""""""
>Its META-INF/MANIFEST.MF looks like:
>========================
>Manifest-Version: 1.0
>Main-Class: Tvc
^^^
should be testpkgjar.Tvc ?
You are correct and thank you! The only things I had to change
were the manifest text (to what you proposed) and the jar command
line:
jar cfm Mvc.jar MyMainClass testpkgjar\Tvc.class testpkgjar\Tmdl.class
Thanks again.