Java: adding references to other projects in the same workspace

Coming from a C# background I couldn’t quite figure out how to reference projects in the same workspace in Java. In C# ( and Visual Studio) it’s as easy as cake to make a reference to a project in the same solution and I figured it had to work in Java as well. Eclipse turned out to have a feature that handles this and I thought I’d just write it down in case I forget and in case you who are reading this need to know :).

If you have a workspace with a couple of projects representing a layer each in a larger application it might look something like this:

 

Now, to make a reference to Test.Core in Test.Data (in order to use the Person class) you simply right click on Test.Data and go to Build Path => Configure Build Path and you will see the following window:

Select the Projects tab
Select the Projects tab

Select the projects tab and click the Add button and you should see the next window, select the project to reference and click Ok:

 

That’s it, now you have a reference to that project! I have yet to figure out where the references are stored and if Eclipse displays them or if you have to go to the output directory to check them out, but there you are. Good luck!

Leave a Reply