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");
    }
}
有帮助吗?

解决方案

In folder src/:

$ javac org/example/Hello.java
$ java org.example.Hello
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top