tags:

views:

76

answers:

3

Hi Guys,

I am trying to compile and run my java application from the command prompt but am having some errors. I change to the bin bin folder thus am running from the bin folder.I tried compiling with :

>> javac foe.java

but i get some errors that it can't find some classes that are been referred to by the above main class.

Do i have to compile all classes that the above main class references? and if so how do i do it? thanks.

+3  A: 

javac looks in the classpath for those classes referenced by your programs.

If you are unfamiliar with the classpath concept, please see the appropriate Java Tutorial section: http://download.oracle.com/javase/tutorial/essential/environment/paths.html

Thorbjørn Ravn Andersen
A: 

In foe.java, what are the import statements at the beginning of that file? If you're using classes that aren't part of the standard Java Runtime (classes whose package name begins with java.) such as classes you made, classes that belong in other libraries (jar files), you must add them to your classpath before compiling, otherwise javac won't be able to find them.

The rule is: if it ain't part of the JRE, you have to be explicit when you compile.

darioo
A: 

if your main file is in c:\path1\mainfile.java

and referenced java file is in c:\path2\reffile.java

from c:\

java -cp c:\path2 c:\path1\mainfile.java

will compile both your files. (i am assuming you are not using any packages)

to run mainfile.java from c:\

java -cp c:\path1;c:\path2 mainfile