m. vokhm
m. vokhm

Reputation: 699

How to share source folders across projects in Eclipse?

There have been already several similar questions asked, yet I have not found a quite satisfactory and working solution. In the local file system, I have two Eclipse projects whose structures are alike, and I want some packages to be shared across them. And:
- I don't want to have multiple copies of source files due to the obvious reasons;
- I don't like very much the idea of adding one project to the build path of the other project, because it would require to hold both of them open all the time and may lead to a mess and unintentional changes in the other project that would be difficult to find and fix afterwards;
- I would not like to take off the common packages into a third project, I want the projects to be fully self-contained;
- the attempts to link folders with source files from one project as virtual folders to the other project leads to impossibility to assign them the right package names (such folders don't form packages and compiler claims that The declared package "com.example.package" does not match the expected package "")
What is the right way to to manage the task?

Upvotes: 0

Views: 2689

Answers (1)

m. vokhm
m. vokhm

Reputation: 699

The solution that I have found acceptable is to link one project to another as a linked source folder (Project properties -> Java build path -> Source tab -> Link source). The linked folder location should be the source root of the linked project (...\project1\src\ or ...\project1\, depending on the linked project settings), where 'com', 'org' etc live; the folder name may be whatever you like.
In my case I needed to partially reproduce the package structure of the old (linked) project and replace some of the old packages with new packages (located in the current project) with the same names. To do so, one should choose the option Update exclusion filters in other source folders to solve nesting. Configuring the filters is not necessary at this stage (and it would not be too convenient now - you would need to write their texts manually), so after adding the linked source you may just press OK.
If you need to exclude some of the packages of the linked source set (I needed in my case) you should configure Inclusion / Exclusion filters.

enter image description here


Now you can point the folders and files of the linked source that you need in you current project, and point ones that should be excluded, using the graphical view of the linked source folder tree (use the Add Multiple buttons).

Upvotes: 1

Related Questions