Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with packages!!!  RSS feed

 
Mehul Mistry
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Can anyone help me problems i'm getting while bundling my project into packages.I've divided my classes itno three packages. The following is the distribution of classes...

package 1: eSearch [2 classes]
GUI.java
ResultPane.java

Both classes has " package eSearch; " as the first line. And to acceses the other packages below it, i've included " import GdInterface.*; " and " import GdInterface.DBdriver.*; " statements.

package 2: eSearch.GdInterface [5 classes]
QueryGD.java
FilterSearch.java
Scheduler.java
AttributeStore.java
CustomParser.java

Here also all classes have " package eSearch.GdInterface; " as the first line of the code. To acceses the lower classes it has " import DBdriver.*; " statement wherever required.

package 3: eSearch.GdInterface.DBdriver [2 classes]
DBConnect.java
ResultStore.java

Here also both classes have " package eSearch.GdInterface.DBdriver; " as the first statement.


The Folder structure for the entire hierarchy is "eSearch/GdInterface/DBdriver".Package eSearch is on topmost level,then in it there is GdInterface package which inturn has DBdriver package.I've also made all classes as public too.

Also i'm using third party jar files for my project.Where to put all the jar files to make them accesible during compiling and running the project.

NOw the problem comes while compiling. In the folder "esearch" (top most in the hierarchy) i compile GUI.java, which is the main class.But immediately it gives the following error......


GUI.java:60: cannot access GdInterface.DBdriver.DBConnect
bad class file: .\GdInterface\DBdriver\DBConnect.class
class file contains wrong class: eSearch.GdInterface.DBdriver.DBConnect
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
DBConnect dBase;
^
1 error


And similarly if i try to compile the classes first in it eSearch/GdInterface forder.Its not getting my classes in different folder.I'm using JDK1.5 on windows XP.

Can anyone help me out with this.I've got deadline to meet. I don't know where i'm going wrong!!!ALSO I WANT TO MAKE THISAS A JAR FILE AFTER COMPILING!!!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For command line compiling your "current directory" needs to be the parent of the first node of the packages. So if your package starts with "eSearch" you might need to be in "src".

See if this tutorial helps.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Off to "Java in General (Beginner)."
 
Mehul Mistry
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stan for ur reply. But i've already kept my files in the in the same forlder structure as shown by u. But its still not compiling.!!! the eSearch folder is the parent of the other two and all the folders contain the respective files too... But still its not compiling!!!
It gives following errors........


GUI.java:5: package eSearch.GdInterface does not exist
import eSearch.GdInterface.*;
^
GUI.java:6: package eSearch.GdInterface.DBdriver does not exist
import eSearch.GdInterface.DBdriver.*;
^
GUI.java :60: cannot find symbol
symbol : class DBConnect
location: class eSearch.GUI
DBConnect dBase;
^
GUI.java:61: cannot find symbol
symbol : class Scheduler
location: class eSearch.GUI
Scheduler schedule;
^
GUI.java:63: cannot find symbol
symbol : class ResultStore
location: class eSearch.GUI
ResultStore[] results;
^
......
....
...
..

do i have to use some classpath!!!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stan said -- but perhaps you didn't notice --- that you must type your compiler commands from the parent directory of "eSearch." If your current directory is "eSearch" when you compile, then you'll get these kinds of errors.
 
Mehul Mistry
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all,
HOw do u compile from the eSearch parent directory???

eg: javac eSearch.GUI.java OR
eg: javac eSearch/GUI.java

Or something else... None of this working. Actually i tried the entire heirarchy with one small prog in each package... it works there.. but not here!!! Stringe.. don't know whats hapenning!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!