You have to make sure that you set the classpath correctly.
Suppose your project is in C:\MyProject, and you have a directory C:\MyProject\classes\x\y\z with a file MainClass.java in there.
First you have to compile your source code from the directory C:\MyProject:
C:\> cd \MyProject C:\MyProject> javac x\y\z\MainClass.java The you run it from the directory C:\MyProject:
C:\MyProject> java -cp . x.y.z.MainClass Note this: You use the
-cp switch to specify the classpath. The dot "." indicates the current directory. So you include the current directory in the classpath.
Then you specify the fully qualified name of your class (the name of your class including the packages in front of it).
If your class needs other classes that are inside JAR files or in a directory somewhere else on your harddisk, you'll have to add those classes to the classpath as well. For example:
C:\MyProject> java -cp .;mylibrary.jar;C:\OtherProject\classes x.y.z.MainClass More info:
How Classes are Found