开发者

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

开发者 https://www.devze.com 2023-01-20 15:42 出处:网络
Given the default classpath: /foo And this directory structure: foo 开发者_如何学运维test xcom |--A.class

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


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.


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消