aspose file tools*
The moose likes Beginning Java and the fly likes Classpath Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Classpath Question" Watch "Classpath Question" New topic
Author

Classpath Question

Jaz Chana
Ranch Hand

Joined: Feb 19, 2008
Posts: 34
I am having trouble getting my head around a classpath issue. If i understand correct, when I want to compile a .java file using the java compiler, I need to either be in the directory that the .java file is in or at least add it to my classpath. So I'm a bit confused when I do the following I get a read error;



What I (think) I am doing is adding the directory where the .java file exists to the classpath so the compiler can see the Test.java file to compile it. However I get the following error;



error: cannot read: samples.quickstart.service.pojo.StockQuoteService.java
1 error



I know that the .java file compiles correctly because I have managed to compile it by invoking the compiler in the same directory as this file. However when I change directories and use the above command it doesn't seem to work. Can someone tell me why??

Thanks
Jaz Chana
Ranch Hand

Joined: Feb 19, 2008
Posts: 34
I got happy, I thought you'd answered my question .

Oh well, I am now a conformist.
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

You have to dig into how Java namespace works.

If you have the class named samples.quickstart.service.pojo.StockQuoteService that is found in the directory c:/Documents/workspaces/test/src/samples/quickstart/service/pojo, then you have to point the classpath to c:/Documents/workspaces/test/src/. Look at classpath as addresses to class-warehouses. The JVM goes into each appointed warehouse and looks at the package declaration as a specification of what shelf to find the class.

So, you are not to point to the shelf itself, but to the entrance of the storage. And the storage can be a directory, zipfile or jar-file.
 
wood burning stoves
 
subject: Classpath Question