O. Blanchet
O. Blanchet

Reputation: 3

Java cannot load a class that is in a package

When I try to execute a Doc class that is located in a package, I get the error message: Could not find or load main class Doc.java

The class is in a test.foo package. I compile it then enter java test.foo.Doc and get the error. I tried setting the classpath to the current directory using java -cp *; test.Doc but it doesn't work either. I don't know what I'm doing wrong. I'm also already in the directory where the class is located.
What am I doing wrong? My CLASSPATH environment variable points to the current directory as well.

Upvotes: 0

Views: 304

Answers (1)

selimssevgi
selimssevgi

Reputation: 196

It works when your Doc.java is placed as:

./test/foo/Doc.java
javac ./test/foo/Doc.java
java test.foo.Doc

Upvotes: 1

Related Questions