File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Directory structure for a file in a package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Directory structure for a file in a package" Watch "Directory structure for a file in a package" New topic
Author

Directory structure for a file in a package

J C upadhyay
Greenhorn

Joined: Nov 24, 2011
Posts: 16
Hi,
I came across a drag and drop question that asks to create a directory structure. The question states: There is a file Zip.java as shown

package w.x;
import w.y.Zoom;
public class Zip{
public static void main(String[] args){
new Zoom().doStuff();
}
}

w.y.Zoom has been compiled and deployed into a JAR file w.jar
The program compiles with the command from the $ROOT

javac -cp w.jar -d . Zip.java

The question asks to create a directory structure and the answer is:
$ROOT
|---------Zip.java
|---------w.jar
|--------w
|----y
|-------Zoom.class

In my opinion Zip.java compiles fine only if the first statement 'package w.x' is commented. With the package statement in place, Zip.java should be saved inside the directory w/x
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
All the files listed looks like present only under the ROOT directory. I think there is some formatting issue in your post.
In my opinion Zip.java compiles fine only if the first statement 'package w.x' is commented. With the package statement in place, Zip.java should be saved inside the directory w/x

No need - for compilation the package structure is not checked.. only while running the Zip class.
J C upadhyay
Greenhorn

Joined: Nov 24, 2011
Posts: 16
Hi John,
I am sorry for that.
I wonder why the directory structure changes when i post, all the pipes shift to the leftmost side. The answer is:
$ROOT
|
|-------[w.jar]-------w-------y-------Zoom.class
|
|-------Zip.java


$ROOT
|
|-------[w.jar]
|-------w-------y-------Zoom.class
|-------w-------x-------Zip.java

However, in this case, the command to compile Zip.java should be
$ROOT>javac -cp w.jar w.x.Zip.java
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Directory structure for a file in a package