This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a file hello.java in an unnamed package. If i compile it using C:\exercise\ex1>javac hello.java, it compiles without any problem. However, if i try to compile it using classpath command it gives a file not found error.
I used the following command:
C:\exercise>javac -cp ex1 hello.java .
Why can't the compiler find hello.java in the specified package?[/size]
I think you're -cp option statement is incomplete. Shouldn't you specify the whole path? Refer to this page for javac's options. Look at the -sourcepath option while you're there.
In fact, you might want to reconsider your use of the CLASSPATH option (-cp) which overrides your normally set CLASSPATH, since it may cause you other problems. It seems the -sourcepath option fits your needs better.
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
If your program is in a package "ex1" (you have a statement: package ex1; in your source file), then you need to put the base directory of the package in the sourcepath (and in the classpath when running it). Not the package directory itself.