Member_2_3676181 used Ask the Experts™
I am trying to compile a java file in command window.
For one file, I can run Javac command and it will generated a new temp.class file. but when try to run with Java temp, it will give me an error that could't find the class?
Any inputs is welcome!

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Radek BaranowskiFull-stack Java Developer

You need to specify local classpath by running

java -cp . Temp

Assuming that you are in a directory with Temp.class file
IT Business Systems Analyst / Software Developer
Top Expert 2015
While setting the classpath explicitly is possibly the solution, the classpath should default to the current directory in your specific case (ie. "java temp") so that might not be the full solution.

Another likely possibility is that your java class "temp" has been declared to be in a package (look inside your file near the top for a line starting with "package"). If so, then you need to have that (and the resulting temp.class) in a directory structure that relates to the package name.

For example, say that your current directory is C:\Java and that your file looks something like the following...


import ...

public class temp ...

Open in new window

Therefore, you need to place in      C:\Java\my\java\package   (and javac should create temp.class there too) and then from the   C:\Java   directory, you would run     java       or        java -cp .

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial