I have an question about the classpath.
Since I work with te command prompt (I compile programmes in MS Dos) I have problems.
For example: I compile programs on D: Java\Bin\<classname.java> .Then I have no problem.
But I want to make a projectmap in the direcory Bin for example "food" where I can put my sourcefiles. I also want to compile the classes in in that folder.
The directory will be: D: Java\Bin\food\<classname.java>
Then I go problems.
How can I set the classpath so that it works?.
Where can I find the classpath?
I can't find it in the book Head first Java.
it a great explanation there!
Let me know if you still find problems.
It is best not to set a system classpath at all, in which case the JVM will take "." (ie current directory) as a default for the classpath. What it means is, if you download some Java files (most commonly in .jar format) which you need for your application, you add the address of those files to your classpath, then the compiler and "java" tool can find those files.
If you want to compile in a particular directory, try this sort of thing, immediately after opening your command prompt window
That will create the directories, then you need to save the .java files in the food directory after writing "mkdir food" and before writing "javac . . ." Note that using the -d option will create subdirectories corresponding to the package names in your .java files. If the BeefSteak class has a dependency in another file, that file must be compiled first. Or tryor similar, orI don't know whether you have to name the classes in any particular order when compiling.
javac -d . BeefSteak,java
You don't need to do anything with the classpath for that sort of compiling.
Then I tried to compile with a command : javac Fruit.java. I got an error but when I compile in the directory D:\Java\Bin the source file Fruit.java with the command javac Fruit.java then it compiles and it makes a class file of Fruit.
Can you explain this?
I don't know how I can compile in anoher directory then the bin-directory.
I also have no classpath. It is no problem I read.
When you get to the bin directory (which is by the way incorrectly named; you should restrict "bin" to directories containing binary files) try cd java\food. It may be that there is an error in your Fruit file. You really ought to say what the error was; "I got an error" doesn't enable us to help at all.
If you have no system classpath set, you ought to leave well alone. Your Java™ installation will work nicely without it. You usually cause more problems than you solve by setting a system classpath.
Campbell Ritchie wrote:He says a Fruit.class file has be created, so it would appear the PATH has been set correctly.
I think part of the problem is that we haven't been given enough detail about what the errors are. And there are lots of spelling errors in the details (eg PATHCLASS).
I got the erorr: "unkown source". I think it has nothing to do with the fact that there is someting wrong with my code but that the compiler cannot found the class I want to compile.
Yesterday I downloaded a programm Blue J (A java programm) and now I have no problems anymore. When I run the Fruit class in another directory then the bin-map it works.
By the way I still have no PATHCLASS...... I appreciate it that you guys are thinking with me. I still don't know what the solution is but I can study further. Thank you for trying to help me.