• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCJP chapter 10 : Development Classpath problem

 
Swapnil Suryakant Prabhavalkar
Greenhorn
Posts: 23
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

One more question from K&B that I am not able to understand.

Question is :

Given the default classpath:

/foo

And this directory structure:



And these two files:





which allows B.java to compile?

According to me, below answer is also valid:

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


Could you please explain me why this will not work? According to me , it should work correctly.

Thanks in advance.
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the current directory is xcom, so when you compile B.java compiler will look for class xcom.A in xcom directory i.e. the compiler will look for foo/test/xcom/xcom/A.java
 
Swapnil Suryakant Prabhavalkar
Greenhorn
Posts: 23
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankit,

Thanks.

Sorry but I didn't understand! If A.java and B.java are in same package then why compiler pre-pends xcom again to A.java?
 
Matheus Souza
Ranch Hand
Posts: 38
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swapnil Suryakant Prabhavalkar wrote:Hi Ankit,

Thanks.

Sorry but I didn't understand! If A.java and B.java are in same package then why compiler pre-pends xcom again to A.java?


If you want to compile the B.java file you need to be in its root folder, so if you're in xcom folder you'll need to do this
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic