Solved

compile java classes with circular dependency

Posted on 2009-07-14
5
403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

705 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