File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes compiling interdependent classes and pachages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "compiling interdependent classes and pachages" Watch "compiling interdependent classes and pachages" New topic
Author

compiling interdependent classes and pachages

Nedyalka Gunderson
Greenhorn

Joined: Apr 21, 2004
Posts: 11
I have two packages, each package is dependent on the other. (Package A uses classes from package B. And package B uses classes from package A.) How can I compile each package, so they see the other dependent package? My compiler says it cannot resolve symbols since it cannot find the compiled packages.

I am using JCreator as my development environment. I don't know how to arrange the packages in directories to resolve these dependencies. Does JCreator require the .java files stored in a particular directory structure? Even classes within the same package can't see each other and I can't compile them.
peter wooster
Ranch Hand

Joined: Jun 13, 2004
Posts: 1033
Originally posted by Nedyalka Gunderson:
I have two packages, each package is dependent on the other. (Package A uses classes from package B. And package B uses classes from package A.) How can I compile each package, so they see the other dependent package? My compiler says it cannot resolve symbols since it cannot find the compiled packages.

I am using JCreator as my development environment. I don't know how to arrange the packages in directories to resolve these dependencies. Does JCreator require the .java files stored in a particular directory structure? Even classes within the same package can't see each other and I can't compile them.


Until you completely understand how directories, packages and classpath are related, you should stay away from IDEs. They hide the real world, make complex problems too simple and simple problems too complex. Use a programmer's editor such as jEdit or TextPad and use Ant to build your project.

For those who will say that I hate IDE's because I've never used one, you are wrong. I've used NetBeans, Forte, Visual Cafe, Borland JBuilder, Oracle JCreator, Visual Studio.Net, VB5, VB6, VC++5, VC++6. These things are like power tools, its easier to cut square corners with a nice Makita compond mitre saw, but its also easier to lose a finger if you don't understand how it works..

What you need to do is build a directory structure from your classpath, eg. if classpath = C:\javadev\SCJD\classes, then you need a directory structure like:

C:\javadev\SCJD
C:\javadev\SCJD\classes\suncertify
C:\javadev\SCJD\classes\suncertify\db
C:\javadev\SCJD\classes\suncertify\gui
C:\javadev\SCJD\code\suncertify
C:\javadev\SCJD\code\suncertify\db
C:\javadev\SCJD\code\suncertify\gui

You put the code in the code subdirectories and ask your IDE to build the classes in the classes subdirectories. You then use the jar tool to build a jar file based on the classes.
Michal Charemza
Ranch Hand

Joined: Jul 13, 2004
Posts: 86
Is having two packages depend on each other a good idea? Somehow it just doesn't sit well with me. Admitedly I don't have much experiance, but it just seems a "messy" way of doing things to me.

Any comments gratefully appreciated.

Michal
peter wooster
Ranch Hand

Joined: Jun 13, 2004
Posts: 1033
Originally posted by Michal Charemza:
Is having two packages depend on each other a good idea? Somehow it just doesn't sit well with me. Admitedly I don't have much experiance, but it just seems a "messy" way of doing things to me.

Any comments gratefully appreciated.

Michal


The OP's problem with packages doesn't go this deep, they have problems with one package depending on another.

That said, its best if you can prevent or reduce such mutual dependencies. The Observer pattern is the most frequently used means of doing this. But one of your packages must still depend on another, eg. your GUI is dependent on your Business layer which is dependent on your network which is dependent on your database.

Frequently you will find that you have interfaces that make callbacks in the opposite direction possible, these can be replaced with the Observer pattern, as AWT does with the addxxxListener methods and anonymous inner classes. If there is never more or less than one listener for an event source, this pattern may add too much complexity.
 
Don't get me started about those stupid light bulbs.
 
subject: compiling interdependent classes and pachages