Reputation: 11
I compiled classes using eclipse, but when I try to run them in the command line, it returns "Cannot find or load main class".Command line.
My class is:
package Chapter10;
public class Hfpd10
{
public static void main(String[] args)
{
System.out.println("it works");
}
}
I am running the command from within the C:\Users\John\Documents\Java\EclipseWorkspace\HeadFirstDesignPatterns\bin\Chapter10 folder, where the class files are. The command is:
java Hfpd10
It runs in eclipse and I used the exact same path.
The only question I could find like this went unanswered. cannot run java file in command line that created by eclipse
Upvotes: 1
Views: 670
Reputation: 11822
Change to the parent directory and run the following command:
java Chapter10.Hfdp10
This required is because your class is in a package and you need to reference it with its full package name.
Upvotes: 1