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.
classpath variable is not defined for both Windows and Linux /Ubuntu/
File -> c:\documents and settings\fbi\desktop\base\B1.java
current directory c:\documents and settings\fbi
java -cp Desktop\base B1 - OK
java -cp "c:\documents and settings\fbi\desktop\base" B1 - OK
java -cp c:\documents and settings\fbi\desktop\base B1 - NOT OK
javac -cp desktop\base\ B1.java - NOT OK
javac -classpath desktop\base B1.java - NOT OK
javac -cp "c:\documents and settings\fbi\desktop\base" B1.java - NOT OK
javac -classpath "c:\documents and settings\fbi\desktop\base" B1.java - NOT OK
current dir to c:\documents and settings\fbi\desktop\base\
javac B1.java - OK
File -> /home/valentino/base/B1.java
current directory "home"
java -cp valentino/base B1 - OK
java -cp /home/valentino/base B1 - OK
javac -cp /home/valentino/base B1.java - NOT OK
javac -cp valentino/base B1.java - NOT OK
javac -cp /valentino/base B1.java - NOT OK
current dir to /home/valentino/base
javac B1.java - OK
So why javac seems to be not working ? What went wrong?
The B1 class is not in any package, so all i need is just to tell the javac where it is, don't I?
The classpath is only used to find compiled classes, not to find source files. So setting the classpath to a directory that contains your source code will not work. You can just enter the whole path to your source file, like this:
Jesper Young wrote:The classpath is only used to find compiled classes, not to find source files. So setting the classpath to a directory that contains your source code will not work.
Thanks, i didn't know -cp is looking only for compiled files and not source,
You can just enter the whole path to your source file, like this:
i did it /I've shown above/ , but still not working
Joined: Aug 23, 2007
if using the absolute path isn't working with javac, you may have a problem with your $PATH variable (Windows environmental variable).
And with the Ubuntu path variable.
Either that or you had a typo. Anyway, the concept is that javac doesn't care about packages so you need to give it an argument
that tells it where the actual .java file is, either a relative path or an absolute path. You don't use -cp with javac, I believe, unless you are
pointing to .class files used for compilation of your .java file.
I did read that if the source file for the class file you point to with -cp is found [in the same directory,] the source file may be recompiled, rather than using the .class file. see the javac man page for more info.