Solved

compile java classes with circular dependency

Posted on 2009-07-14
5
395 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now