How to share Eclipse project preferences between u

2019-03-26 15:35发布

问题:

We have several devs in the team, the source code is managed using the Mercurial DVCS.

The .metadata folder is not under the source control.

The problem, is that when I configure project dependencies (jars, user libraries, source code paths, etc ...) they are stored inside the .metadata folder, namely in .metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.core.prefs

Since this file is not managed by DVCS, all the devs need to repeat the project configuration process all over again. For a new dev in the team this is a major head ache.

My question is there a sane procedure to share this kind of configuration data? I am new to the world of Java and Eclipse, so maybe I am missing something really basic here.

EDIT

The problem is that I have been using User Libraries, which are defined globally and thus are not shared. Using External Jars solves the problem, because these are recorded in the .classpath file inside the project directory.

回答1:

You can specify a lot of properties in the project configuration instead of in the global configuration. Just right-click on the project and select "Properties" there.

Eclipse then saves the preferences in the project directory instead of in the workspace configuration directory. That way you can check-in the project specific configuration into your SCM and share it with other project members.



回答2:

You can prepare a preferences file (.epf) and store it in source control. Each developer will have to import this file once in each workspace they're using.

To create a preference file, go to File → Export... → General → Preferences. You can then edit the .epf file, so that it only contains the preferences you want to share with everyone. This way you can share code style preferences, formatting options, compiler warnings, JRE settings, UI tweaks, and many more types of Eclipse preferences.



回答3:

A short answer would be - use an IDE-independent project configuration tool like Maven.

Another possibility is ant - a very powerful build tool. Slightly out-of-vogue lately.

Sharing the buidfiles used by such a tool is a very common option for making your project settings and dependencies managable and easily portable.

Sharing the eclipse-generated metadata is on the other hand discouraged as eclipse stores dependencies with their absolute pathes (not sure if this is always the case, but definitely sometimes), and those pathes can cause a set of issues (experienced first-hand). Especially if shared between OS borders (win-linux)