• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin


Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Contact.java:24: 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?
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Thomas,
    Bookmark Topic Watch Topic
  • New Topic