Space
Space

Reputation: 1040

Running a Java code in cmd is not working while everything is fine in Eclipse

I wrote the code below in Eclipse and trying to do the same in cmd. However I in cmd the error message :

Error: Could not find or load main class GetMousePosition.

In cmd, I am in the folder where they class is : c:\Java\Examples\src\Robots\

When I compile the class (doing : javac GetMousePosition), everything works fine.

Originally, I set up my java's bin folder path in the environment variables.

Thanks in advance for your help

package Robots;

import java.awt.*;
import java.awt.event.*;

public class GetMousePosition {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println(MouseInfo.getPointerInfo().getLocation());
    }

}

Upvotes: 0

Views: 119

Answers (3)

Diego Basch
Diego Basch

Reputation: 13069

You need to back up one directory (to c:\Java\Examples\src\) and then run

java Robots.GetMousePosition

Upvotes: 2

jtahlborn
jtahlborn

Reputation: 53694

You need to provide the full class name on the command line, in this case Robots.GetMousePosition. java may also assume that your class is in the right directory structure, so you should probably move up one directory.

Upvotes: 2

Mukul Goel
Mukul Goel

Reputation: 8467

The problem is that you need to specify the main class. Eclipse can not find the class that has a main method.

For this you need to

Right click the file in the view -> run as -> Run configuration and there you need to select the class that has main method.

For detailed guide follow this: Set Eclipse launch configuration

Upvotes: 0

Related Questions