80

I'm working on two projects in eclipse and I would like to import some classes from project a to project b. What should I do?

Is there a way of doing it without adding the project to the build path ?

Apple Grinder
  • 3,573
  • 7
  • 22
  • 35
David B
  • 29,258
  • 50
  • 133
  • 186
  • can you clarify how to import class from another project ? I'm getting error The import can not be resolved – vikramvi May 22 '17 at 14:42
  • Found the problem; I didn't specify any package for class in the project which I had included under Projects. Found this issue through https://stackoverflow.com/questions/2335211/what-is-the-default-package-in-which-my-classes-are-put-if-i-dont-specify-it – vikramvi May 22 '17 at 15:39

1 Answers1

103

add project A to project B's build path.

Follow these steps:
Edits by @David B
Right click on project B's folder in eclipse --> properties --> build path --> projects --> add.
Now add project A

Ahmed Hamdy
  • 2,547
  • 1
  • 17
  • 23
ozk
  • 2,025
  • 1
  • 15
  • 11
  • 48
    thanks! just to be more explicit for future reference of other readers: right click on project b's folder in eclipse --> properties --> build path --> projects --> add. – David B Aug 15 '10 at 13:52
  • i followed your solution and i got `a cycle was detected in the build path`. – bouncingHippo Apr 25 '13 at 14:26
  • 1
    By `Build Path` do you mean `Java Build Path`? – CodyBugstein May 23 '13 at 21:09
  • 1
    There's some trouble following [ozk](http://stackoverflow.com/users/408717/ozk) solution but [David B](http://stackoverflow.com/users/377031/david-b) is much better. – mr5 May 15 '14 at 01:45
  • 1
    @bouncingHippo I think that mean you have both files importing each other. – Carcigenicate Nov 30 '14 at 20:14
  • What about adding a dependency via pom file? Mine is a maven project. – R11G Sep 07 '16 at 00:22
  • can you please clarify how to import class from project a into the class of project b ? Classes which I want to import are public – vikramvi May 17 '17 at 15:41
  • Found the problem; I didn't specify any package for class in the project which I had included under Projects. Found this issue through https://stackoverflow.com/questions/2335211/what-is-the-default-package-in-which-my-classes-are-put-if-i-dont-specify-it – vikramvi May 22 '17 at 15:40
  • When using PyDev: Right click on project folder -> PYTHONPATH -> External Libraries -> Add Source Folder – smcs Aug 02 '17 at 15:14