It's not a secret anymore!
The moose likes Java in General and the fly likes PACKAGE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "PACKAGE" Watch "PACKAGE" New topic


thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
Hi All,
Given below are the steps followed:
1) I have one class that is stored in a directory structure given below:
2) I set class path like this: D:\WebSphere\AppServer\installedApps\globalrfx.ear\global.war\WEB-INF\classes\;
3) And I put my first statement in that class as given below
package com.sharedapps.globalrfx.beans.service.modify;
It compiled fine
4) I have got another class up in the hierarchy as given below:

6) This also compiled fine
7) And What I did is I append classpath as given below
8) And I removed package declaration from top of class ChangeDB,It again compiled fine.(removed package com.sharedapps.globalrfx.beans.service.modify;
9) But When I try instantiate ChangeDB in Contact class and I imported all classes from modify where class ChangeDB LOCATED. import com.sharedapps.globalrfx.beans.service.modify.*; I got error as given below cannot access com.sharedapps.globalrfx.beans.service.modify.ChangeRemoveATMDB
bad class file: J:\WebSphere\AppServer\installedApps\globalrfx.ear\global.war\WEB-INF\classes\com\sharedapps\globalrfx\beans\service\modify\ChangeDB.class
class file contains wrong class: ChangeDB
Please remove or make sure it appears in the correct subdirectory of the classpath.
ChangeRemoveATMDB objDB = new ChangeRemoveATMDB();
Even though I imported the class, why I am getting above said error? I set the classpath till where the class is situated. Now JVM can see where the class is located and that can be accessed from that package also.
But When I added the package statement again in ChangeDB.class,
It compiled fine!!! I was able to access the same class from the class Contact in other folder D:\WebSphere\AppServer\installedApps\globalrfx.ear\global.war\WEB-INF\classes\com\sharedapps\globalrfx\beans\common\
How does JVM locate the classes and how does it load the class?
Why package declaration is necessary even if I set classpath till that point where class is resided? Can anybody explain about the relationship between classpath, package declaration et all?
Dhamodharan Krishnan

Joined: Nov 07, 2001
Posts: 23
Hi Thomas,

Dhamodharan Krishnan,<br />Sun Microsystems, Bangalore<br />Direct : 91-80-4184 7247<br />Cell : 91-99 80 147 600
I agree. Here's the link:
subject: PACKAGE
It's not a secret anymore!