如何从 Eclipse 项目中排除一些文件夹?

我正在添加一个 Eclipse 项目到我们现有的代码库中,我想知道是否有一种方法可以排除一些目录被 eclipse 拾取?原因是我们的存储库中有一个巨大的“第三方”目录,这个目录不能出现在我们正在使用的 结对编程插件的项目中,因为这个插件能够有效地同步。

有线索吗?

62913 次浏览

Yes, you may place a custom filter on your project. In your project explorer view, there should be a white, downwards pointing arrow near the top of the panel by the Package Explorer tab. Click it, and go to Filters. From there, you can specify certain folder patterns you do not want detected by checking the box next to Name Filter Patterns. In this case, I would put the name of the 3rd party library.

Filters will hide resources from view, but they're still in the project. If you create a project in another location you can create linked resources to the folders you want to include in your project.

For reference I posted another answer that describes how to use linked resources in more detail.

The way I've always done it is to explicitly check out projects as peers. e.g:

~/myworkspace/goodproject
~/myworkspace/3rdparty

then import only "goodproject" into eclipse. If "3rdparty" is a subdirectory of goodproject, you can fake it out... Say for example your svn project looks like this:

project/
src/
main/
3rdparty/

You can locally create project/src/ then checkout only the "main" directory, and have eclipse rely on a packaged version (e.g. point to the jar if your project is java).

There is a straight way to do it:

  1. Right-click a project folder in Project Explorer tree and go to "Properties".
  2. Resource -> Resource Filters.
  3. Add as many exclusion filters for files/folders as you like.

P.S. If your project tree is not updated automatically you may have to press F5 while having input focus in Project Explorer window.

If you want to add filters directly inside .project file, these are some rules:

    <type>6</type> <!-- exclude all, files -->
<type>5</type> <!-- include only, files -->
<type>13</type> <!-- include only, files and folders -->
<type>26</type><!-- exclude all, folders, all children -->


<arguments>1.0-name-matches-false-false-xyz</arguments> <!-- case sensitive=false, regular expression=false, something named=xyz -->
<arguments>1.0-name-matches-true-false-EEE</arguments> <!-- case sensitive = true, regular expression = false, something named=EEE -->
<arguments>1.0-name-matches-false-false-www</arguments> <!--case sensitive=false, regular expression = false, something named=www -->

One .project filter section for example:

    <filteredResources>
<filter>
<id>1567020347706</id>
<name></name>
<type>6</type> <!-- exclude all, files -->
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-abc</arguments>
</matcher>
</filter>
<filter>
<id>1567020347708</id>
<name></name>
<type>5</type> <!-- include only, files -->
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-xyz</arguments> <!-- case sensitive=false, regular expression=false -->
</matcher>
</filter>
<filter>
<id>1567020347711</id>
<name></name>
<type>13</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-mno</arguments>
</matcher>
</filter>
<filter>
<id>1567020347713</id>
<name></name>
<type>26</type><!-- exclude all, folders, all children -->
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-true-false-EEE</arguments> <!-- case sensitive = true, regular expression = false -->
</matcher>
</filter>
<filter>
<id>1567020347716</id>
<name></name>
<type>26</type> <!-- exclude all, folders, all children -->
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-www</arguments> <!-- case sensitive = false, regular expression = false -->
</matcher>
</filter>
</filteredResources>

Right click on the root folder of all the files / folders you want to exclude and select Build Path and exclude

exclude