user479380
user479380

Reputation: 1

SCJP Sun Certified Programmer for Java 6 Study Guide (Exam 310-065) example from chapter 10 Development "-classpath"

Given the default classpath:

/foo

And this directory structure:

foo
  |
 test
    |
   xcom
     |--A.class
     |--B.java

And these two files:

package xcom;
public class A { }

package xcom;
public class B extends A { }

Why it doesn't work?

javac -cp test xcom\A.java

Upvotes: 0

Views: 617

Answers (3)

Tomas Narros
Tomas Narros

Reputation: 13468

The file A.java doesn't exist. You have the compiled class file instead (file A.class)

With the folders and files you have posted, you only could compile B.java:

javac -cp test xcom\B.java

Upvotes: 0

rsp
rsp

Reputation: 23373

Because A.java is not present in the foo/test/xcom folder?

Upvotes: 0

matt b
matt b

Reputation: 139931

Because the -classpath argument to the javac compiler tells the compiler where to find already compiled files that your code uses, not where to find the files you want to compile. Use the -sourcepath argument instead.

And in the future, when you post a question about something that "doesn't work" please include the exact information about what errors you get, what the tool outputs, etc. - to enable people to more easily help you.

Upvotes: 3

Related Questions