This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes compiling 2 classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "compiling 2 classes " Watch "compiling 2 classes " New topic

compiling 2 classes

Robert Darling
Ranch Hand

Joined: Jun 21, 2008
Posts: 100

There is a question from the KB book "CHAPTER 10 DEPLOYMENT"
The first class is GetJar

The second class is Foo

The question asks that given a directory structure as below, how would you compile both classes

test -
    | -MyAPP|

Suppose that we are in the test folder.
How would we compile both file.

to compile we would cd to the test folder and

How would we compile the Since its in a different package. The solution given in the book says

javac MyApp/
//Place into test a jar file that contains MyApp/Foo.class
javac -classpath MyJar.jar
java GetJar

But its not working. It does work if i remove the package statement from the Foo class. In the file Foo.d is accessed without importing the MyApp package. Is the question correct. I have tried to replicate the question as closely as possible.

Kind Regards
Javier Cortes

Joined: May 26, 2010
Posts: 6
I believe class GetJar is missing an import:
Moguluri Ravi Kiran
Ranch Hand

Joined: Apr 16, 2010
Posts: 62

XXX\test>javac -cp=.;.\MyApp;

Mark Moge
Ranch Hand

Joined: Mar 14, 2009
Posts: 96

For the record:
- there is no problem with any package statement
- there is a mistake in the book and the A answer should be (Unix)

if you want to try it on a Windows

It is sorta covered in the JavaRanch Style Guide.
subject: compiling 2 classes
Similar Threads
ch10 q11
Confusion over java classpath
Doubt at K&b chapter 10,question 11
Do we need to provide classpath for jar file with java command if jar file is in current directory?
Error in Sun Certified Programmer for Java 6 Study Guide