Solved

compile java classes with circular dependency

Posted on 2009-07-14
5
396 Views
Last Modified: 2012-05-07
I am using JavaCompiler from apache commons jci.

How are you suppose to take care of multi pass compilation especially when you have circular dependency between two java classes. A calls B, and B calls A. is there an order or particular way to call the compiler, so it will take care of the circular dependency?
0
Comment
Question by:bhomass
  • 2
  • 2
5 Comments
 
LVL 24

Accepted Solution

by:
sciuriware earned 150 total points
ID: 24853710
Trust me it works in only 2 passes:
1) to make up references,
2) to fulfill the referenced classes.

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 24853732
Btw.: for almost any OS I recommend SUN's JDK 6.

Other remark: classes do not call each other, but call each others' methods.
That makes it easy to compile the lot in 2 runs.

A a = new A(); // Calls the constructor.

;JOOP!
0
 

Author Comment

by:bhomass
ID: 24853871
I don't see any api that will run 2 passes. if I use
compile(java.lang.String[] pResourcePaths, ResourceReader pReader, ResourceStore pStore, java.lang.ClassLoader pClassLoader)

will it automatically run twice?
0
 
LVL 2

Assisted Solution

by:ethnarch
ethnarch earned 100 total points
ID: 24855195
I am trying to figure out what your unique case is as there might be a better way to create these classes.  I would stay away from any classes that are that highly dependant.  Better practice would be to have in intermediary, but it's hard to tell without knowing what you are actually trying to accomplish.

Beyond that though why don't you just try compiling the code and then post the errors if any.  
0
 

Author Comment

by:bhomass
ID: 24855356
wonderful. by talking thru this with you guys, I walked into the answer.

indeed the api I posted does the job.

thanks.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JList custom Cell Renderer refresh 15 57
servlet filter example 37 63
Java string replace 11 48
maven module vs maven project 3 23
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question