aspose file tools*
The moose likes Beginning Java and the fly likes More package questions... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "More package questions..." Watch "More package questions..." New topic
Author

More package questions...

Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
I'm still struggling with packages, so I thought I'd come to the friendly Ranch...
Let me start by saying that I do understand the basics. I know I need a package statement, I know the packages basically refer to a directory strucutre and have all kinds of benefits.
Let's say I have a package "com.myDomain.myPackage.subPackage"... I assume that I have to emulate this directory structure somewhere on my PC?
Let's say on my PC I have this in "C:\JavaSource\Development", do I need to compile these in the "C:\JavaSource\Development\com\myDomain\myPackage\mySubPackage" diretory?
And what happens when I implement this to another machine and the parent directory isn't the same... nothing? Am I correct in thinking I can simply copy the "com" directory (or put it in a .jar) in order to implement?
I know this shouldn't be so hard but this is really fuzzy for me right now...
TIA,
Joel


Wait a minute, I'm trying to think of something clever to say...<p>Joel
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Joel, I think you got it quite right!


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Mohan Panigrahi
Ranch Hand

Joined: Sep 28, 2001
Posts: 142
Hi Joel,
That is correct. To add some more :

Let's say on my PC I have this in "C:\JavaSource\Development", do I need to compile these in the "C:\JavaSource\Development\com\myDomain\myPackage\mySubPackage" diretory?
And what happens when I implement this to another machine and the parent directory isn't the same... nothing?

Yes. This is because the class file will not contain information about the directory structure used to compile it.
Also, as you might already know, it is not necessary to go to that particular directory where java file is lying to compile it. As for example if your file name was Ex4.java, the following statement would compile as well
javac com\myDomain\myPackage\subPackage\Ex4.java
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
Thanks for the replys. I just needed someone to confirm that what I thought was correct. This should be a simple concept but I had struggled with it so much off an on that I just didn't trust myself.
Thanks again,
Shivade Sanjay
Greenhorn

Joined: Apr 09, 2002
Posts: 6
Hi Joel
Let me add something to your previous dicusssions.
You do not have to create directory structure manually if you are not using some kind of tool. The javac compiler has a option -d dir which after compilation of the class puts classes in respective folder as per specified in package in .java file.
eg. My java file (dt.java) has this code
package MyJava.dt;
import java.text.*;
import java.util.*;
import java.sql.*;

public class dt
{
.
.
.
while compiling I will say
javac dt.java -d C:\Test
so it creates subdirectories MyJava\dt under C:\Test folder.
It's so easy..
You might be knowing this .. but thought just let you know ...
Thanks
Sanjay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: More package questions...