Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classpath Question

 
Jaz Chana
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got happy, I thought you'd answered my question .

Oh well, I am now a conformist.
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic