aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes package problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "package problem" Watch "package problem" New topic
Author

package problem

sharma ishu
Ranch Hand

Joined: Sep 10, 2012
Posts: 70
foo
|
test
|
xcom
|--A.class
|--B.java
And these two files:

package xcom;
public class A{}

package xcom;
public class B extends A{}

Please explain why does the following invocation does not work?

Set the current directory to test then invoke:
javac -classpath xcom:. B.java
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 813
    
    1
The javac looks throu classpath (xcom and current path), but it cannot find B.java
The command is : javac -classpath xcom:. xcom/B.java

When using javac to compile a file, specify the exact path of the file you want to compile. The classpath only specify the path where the supporting class is, which is A.class.
sharma ishu
Ranch Hand

Joined: Sep 10, 2012
Posts: 70
Himai Minh wrote:The javac looks throu classpath (xcom and current path), but it cannot find B.java
The command is : javac -classpath xcom:. xcom/B.java

When using javac to compile a file, specify the exact path of the file you want to compile. The classpath only specify the path where the supporting class is, which is A.class.

So you mean to say that classpath can help locate only .class files and not .java files? Or am I wrong?
Konrad Till
Greenhorn

Joined: Nov 20, 2012
Posts: 7
That's right.
sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58

Himai Minh wrote:The javac looks throu classpath (xcom and current path), but it cannot find B.java
The command is : javac -classpath xcom:. xcom/B.java

When using javac to compile a file, specify the exact path of the file you want to compile. The classpath only specify the path where the supporting class is, which is A.class.


If xcom would have been the current directory then i guess the foll. would work -
javac . B.java
i guess so. OR if the import xcom.A; would have been there in class A source code. please rectify if i am wrong.


Always believe in yourself
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

sarvesh dikonda wrote:
Himai Minh wrote:The javac looks throu classpath (xcom and current path), but it cannot find B.java
The command is : javac -classpath xcom:. xcom/B.java

When using javac to compile a file, specify the exact path of the file you want to compile. The classpath only specify the path where the supporting class is, which is A.class.


If xcom would have been the current directory then i guess the foll. would work -
javac . B.java
i guess so. OR if the import xcom.A; would have been there in class A source code. please rectify if i am wrong.


javac . B.java this won't work. i suppose you really wanted to say javac -classpath . B.java. assuming you forgot to mention the classpath switch , still it wont work. why ? it will be able to find B.java but what about A.class. you gave the classpath as current directory i.e. xcom and it will search for A in xcom like this - it will look for directory named xcom which contains A.class, but it won't find xcom in xcom. as a general rule the classpath should contain the PARENT OF THE PACKAGE ROOT. now since the package of A is xcom and the parent of xcom is test, the test directory should have been in classpath .so the command would be

javac -classpath ../ B.java (assuming you are in xcom directory).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package problem