0

The file Hello.java :

package org;

public class Hello {
    public static void main(String args[]) {
        System.out.println("Hello world !");
    }
}

Is alone in a directory C:\Users\hj\dev\java and is compiled using :

java Hello.java

It generates the file C:\Users\hj\dev\java\Hello.class in the same directory.

When I try to run :

javac Hello

It returns :

Error: Could not find or load main class .\Hello.class

Caused by: java.lang.ClassNotFoundException: /\Hello/class

The dir returns :

PS C:\Users\hj\dev\java> dir
    Directory : C:\Users\hj\dev\java
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       08/01/2020     16:33            421 Hello.class
-a----       08/01/2020     16:33            126 Hello.java

But it works when I remove package org; from the source code.

Do you know how to run a class defined in a package ?

Community
  • 1
  • 1
vizkel
  • 13
  • 1

0 Answers0