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?
You ought not to compile anything in the "bin" directory. You ought to create your own directory to put your work in.
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
mkdir java cd java
javac -d . BeefSteak,java
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.
You don't need to do anything with the classpath for that sort of compiling.
Joined: Aug 10, 2010
I put my sourcefiles Apple.java and Fruit.java in the food map directory D:\Java\Bin\Java\food
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.
Joined: Oct 13, 2005
Maybe you have two files called Fruit.java
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.