File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "compiling 2 classes " Watch "compiling 2 classes " New topic
Author

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 -
    | GetJar.java
    | -MyAPP|
            |Foo.java

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

to compile Foo.java we would cd to the test folder and


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

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


But its not working. It does work if i remove the package statement from the Foo class. In the GetJar.java 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
Greenhorn

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; GetJar.java Foo.java

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


SCJP6 | http://programmerutilities.blogspot.com/
 
 
subject: compiling 2 classes