File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 63

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

Mark Moge
Ranch Hand

Joined: Mar 14, 2009
Posts: 100

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

I agree. Here's the link:
subject: compiling 2 classes
It's not a secret anymore!