开发者

Java can't find class errors in compilation

开发者 https://www.devze.com 2023-01-22 14:47 出处:网络
I am trying to compile and run my java application from the command开发者_Python百科 prompt but am having some errors. I changeto the bin bin folder thus am running from the bin folder.I tried compili

I am trying to compile and run my java application from the command开发者_Python百科 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.


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号