File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classpath

 
Punit Singh
Ranch Hand
Posts: 952
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
4. 3. Set the current directory to test then invoke
javac -classpath xcom/B.java

5. Set the current directory to test then invoke
javac -classpath xcom: . B.java



4. Set the current directory to test then invoke
javac -classpath xcom/B.java

It will not compile as it is incorrect syntax, as it has written nothing after -classpath.


5. Set the current directory to test then invoke
javac -classpath xcom: . B.java

See Abhi carefully why it will not compile. -classpath is used to search only .class files, means here it is only set to help B.java to find A.class file.
So -classpath is not used to search B.java, its ok.
Now we are in test directory and B.java is in xcom directory and we have not written xcom/B.java, so javac will try to find B.java in test directory, so it will fail to find B.java. that's it.

And now my humble request for you to make all the directory structure and run all the cases from command line, otherwise it will make you confused always.
 
Sachin Adat
Ranch Hand
Posts: 213
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Punit Singh wrote:Why Sachin? I think B.java will be able to find xcom.A class as xcom package is in test directory itself.

The problem is the classpath is set to foo, but the compiler is looking for xcom.A for B.java to compile, which is found in test.

as for point 4 is a typo I had earlier mentioned.
 
Abhi vijay
Ranch Hand
Posts: 509
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, windows.
 
Punit Singh
Ranch Hand
Posts: 952
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin Adat wrote:
Punit Singh wrote:Why Sachin? I think B.java will be able to find xcom.A class as xcom package is in test directory itself.

The problem is the classpath is set to foo, but the compiler is looking for xcom.A for B.java to compile, which is found in test.

as for point 4 is a typo I had earlier mentioned.


Ok I missed that /foo part, Abhi Sachin is right here.
 
Punit Singh
Ranch Hand
Posts: 952
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhi vijay wrote:No, windows.


Then why are you using : in classpath.
javac -classpath xcom:. xcom/B.java.

You should use ; there.
javac -classpath xcom;. xcom/B.java.
 
Abhi vijay
Ranch Hand
Posts: 509
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Punit and Sachin for helping me out.
I am really sorry for wasting your time. But I was really confused. The explanation given in K & B was confusing. I interpreted things differently especially the current directory and cp.

Now , I have clearly understood the topic. Thanks to uou Guys.
 
Ruben Soto
Ranch Hand
Posts: 1032
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the discussion guys. Unfortunately I am confused about something very basic regarding classpaths, so I am starting a new topic on it.
 
Ruben Soto
Ranch Hand
Posts: 1032
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sachin Adat wrote:
Ruben Soto wrote:
Only answer 3. is correct. Why? Because you must include test in the classpath. That's the only answer that includes test in the classpath. Do you understand why test must be in the classpath?

For finding xcom.A you need to have test in classpath or atleast you have to be in test directory which Punit pointed out, but it is not in the options.
So I think you were right.

Correct me if I am wrong.....


Sachin,

What I find very confusing is that I thought that the current directory was never implicitly searched, but that it had to be added explicitly to the classpath. I have started another thread for this question.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic