Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Classpath" Watch "Classpath" New topic
Author

Classpath

Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
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.


SCJP 6
Sachin Adat
Ranch Hand

Joined: Sep 03, 2007
Posts: 213
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.


SCJP 6
How To Ask Questions On Java Ranch - How To Answer Questions On Java Ranch
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
No, windows.
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
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

Joined: Oct 16, 2008
Posts: 952
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

Joined: Sep 16, 2008
Posts: 509
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

Joined: Dec 16, 2008
Posts: 1032
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.


All code in my posts, unless a source is explicitly mentioned, is my own.
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Classpath
 
Similar Threads
Ch. 10 Development question
Doubt in classpath statement....
Classpath Related Question
Plz help me in solving the problem of JAVAC comand
Classpath - Question 1