Macjay
Macjay

Reputation: 11

Cannot run class files compiled by eclipse in command line

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.

Eclipse 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

Answers (1)

Jason
Jason

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

Related Questions