?
Solved

compile java classes with circular dependency

Posted on 2009-07-14
5
Medium Priority
?
404 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 600 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 400 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

764 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