Frage

This is my first project with Java. I'm using Ubuntu.

I'm in the folder /home/anis/jtest/myProject and I run the Hello.java file with :

javac src/org/example/Hello.java

Seems that works. I get no error and a Hello.class file in the example directory.

Then from the myProject firectory again I run :

java -cp src/org/example Hello

and I get the error : Exception in thread "main" java.lang.NoClassDefFoundError: Hello (wrong name: org/example/Hello)

My code for Hello.java is :

package org.example;

public class  Hello  {
        public static void main(String[] args)  {
            System.out.println("Hello\n");
    }
}
War es hilfreich?

Lösung

In folder src/:

$ javac org/example/Hello.java
$ java org.example.Hello
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top