Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do we need to provide classpath for jar file with java command if jar file is in current directory?

 
Matloob Hussain
Ranch Hand
Posts: 37
Java MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I consider the example from SCJP Sun Certified Programmer for Java 6 Study Guide by Katherine Sierra and Bert Bates (K&B) Page number 817, Chapter 10 and Question no 11. The correct answer according to the book is option A.

The second command is java GetJar, my quesion is how does it find the MyJar.jar without providing classpath or does it use the current directory as used for GetJar.class but it does not work.

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.)

Answer:
A.
javac -classpath MyJar.jar GetJar.java
java GetJar


Thank you.

 
Jack Tol
Greenhorn
Posts: 24
Android Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an error in the question. You indeed have the provide the jar in a classpath. See this topic for more detail.
 
Matloob Hussain
Ranch Hand
Posts: 37
Java MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jack.................
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic