I have a program that resides in a directory that is not set in the path/classpath – and I want to execute it using the -cp option on my console. But I get the NoClassDefFoundException, regardless of what I set as -cp
- out
`- de
`- my
`- package
`- MainClass.class
I navigate into the package directory and try to execute the main class using
MyBook-Pro:out flopes$ java -cp . de.my.package.MainClass
What am I doing wrong here?
The classpath must contain
If your package is
de.my.package, the root isde, and the directory containingdemust be in the classpath.So, if you’re in the
packagedirectory, the classpath should be set to../../..: theoutdirectory is the one that should be in the classpath.Or you should use
.as the classpath, but launch your program from theoutdirectory.