I wrote a Java program, and it successfully compiles and runs in NetBeans, but I'm not able to do the same in the command line, on Windows XP.

It works ok with 1 class, but when I have few files 'package' I have a problems.

1.Start -> run -> cmd
2.Go to dir:

cd [B]C:\Program Files\Java\jdk1.6.0_16\bin[/B]

3.Now I'm trying to compile a package:
(my package is this:

test/Main.java
test/Hotel.java

I do compile my package:

[B]javac test\*.java[/B]

Then I try to run compiled package:

[B]java test\Main[/B]

Also trying:

[B]java test[/B]

But allways is errors only:

C:\Program Files\Java\jdk1.6.0_16\bin>java test\Main
Exception in thread "main" java.lang.NoClassDefFoundError: test\Main/class
Caused by: java.lang.ClassNotFoundException: test\Main.class
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: test\Main.class.  Program will exit.

===============
Source codes

package test;
public class Main {
	static int SPEED = 300; // ms

    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("Loading");

		// Run hotels'live
		Hotel.do_live(SPEED);
    }
}
package test;

public class Hotel {
	public static void do_live(int wait)
	{
		System.out.println("\n\rHotel was finished");
	}
}

------------
If I have only one file(class), then all is ok:

javac TestJava.java
java TestJava

So how I can build the Java package in command line.

java test.Main

not

java test\Main

Thanks. I would never believed that it was so easy to fix :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.