Reputation: 11
I am writing an application in Java and i have two projects say P1 and P2 . I want to access classes of P2 in P1 and access classes of P1 in P2. I have tried adding P1 in P2's build path and vice verse but it is not working,probably we cant add projects to build paths circularly.How do i solve this problem.I was thinking to make a third project and put the classes required in them,add P3 to P1 and P2. But can i do this without creating any additional projects.I am using eclipse Juno.
Upvotes: 0
Views: 200
Reputation: 157
As Elliot Frisch said you, you are creating a circular dependency. I strongly recommend you avoid this too. Here you are information about what circular dependency means:(http://en.wikipedia.org/wiki/Circular_dependency)
I recommend you to create a third project and implement the use of the other two projects. I think that this is the correct way.
If you want use P1 and P2 in P3 you can add to P3 project P1 and P2 projects as dependencies.
Upvotes: 0
Reputation: 1648
I would create a third project, that contains the classes you need to access in P1 and P2. If needed you could create a fourth, fifth,... project if you notice project three is a collection of classes that aren't related to eachother, think Multilayered and Seperation of concern.
I would avoid adding a circular depency from P1 to P2 and from P2 to P1. see: question1 and question2
Upvotes: 0
Reputation: 1330
For accessing classes of different projects you may require to build jar file of that project i.e. P1 and put that jar file into build path of another project let's say P2. Than build P2 project. Now your are able to access classes of P1 Project into Project P2.
Upvotes: 1