hi all,
If i have a directory set as default classpath,and in that directory i have a class file,and a jar file.The class file uses the classes of jar file to compile and run.
Then while compiling and running by commands javac and
java respectively,should i include the classpath for the jar file?
Actually i was confused regarding a question in k&B book----
The Question is:
11. Given the following directory structure:
test-|
|- GetJar.java
|
|- myApp-|
|-Foo.java
And given the contents of GetJar.java and Foo.java:
3. public class GetJar {
4. public static void main(
String[] args) {
5. System.out.println(myApp.Foo.d);
6. }
7. }
3. package myApp;
4. public class Foo { public static int d = 8; }
If the current directory is "test", and myApp/Foo.class is placed in a JAR file called MyJar.jar
located in
test, which set(s) of commands will compile GetJar.java and produce the output 8?
(Choose all that apply.)
A. javac -classpath MyJar.jar GetJar.java
java GetJar
B. javac MyJar.jar GetJar.java
java GetJar
C. javac -classpath MyJar.jar GetJar.java
java -classpath MyJar.jar GetJar
D. javac MyJar.jar GetJar.java
java -classpath MyJar.jar GetJar
Now,as the correct answer is A,my question is ,why are we including the classpath for .jar while compiling and not while running,if we need to include files from .jar while compiling?
and why is option C not correct if i include the classpath while running?
GREAT CONFUSION.Please help me out
THANKS in advance....