package com.testpack; public class Test1 { public static void main(String[] args) { System.out.println ("Run Test1.main()"); } }
It is in d:\dir\com\testpack directory, and classpath is: set classpath=.;d:\dir; It compiles within d:\dir\com\testpack directory, but when I try to run it I get errors:
Exception in thread "main" java.lang.NoClassDefFoundError: Test1 (wrong name: com/testpack/Test1) at java.lang.ClassLoader.defineClass0(Native Method)...
You did right. the class com.testpack.Test1 must be called by
java -cp .\ com.testpack.Test1
BUT: You can't call it from "d:\dir\com\testpack"
Instead, call it from "d:\dir\".
d:\dir>java -cp .\ com.testpack.Test1 will work
If you want to call it from any directory: java -cp d:\dir\ com.testpack.Test1 should also work
"set classpath= ..." does not allways work. If I'm not wrong, java 1.4+ does ignore it completely. Instead you should use the classpath setting from java.exe as shown above.