• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How works the classpath

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear friends,
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.
 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out:
http://faq.javaranch.com/java/HowToSetTheClasspath

it a great explanation there!
Let me know if you still find problems.

Regards,
John Eipe
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
mkdir food
cd food
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.
 
Frank Thuring
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd like to hear some feedback about this closed post too.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Frank Thuring
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.






 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic