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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1187868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:51:26  来源:igfitidea点击:

How can I exclude some folders from my Eclipse project?

eclipseproject

提问by jkp

I'm adding an eclipse project to our existing code-base, and I'd like to know if there is a way to exclude some directories from being picked up by eclipse at all? The reason is that we have a huge "third-party" directory in our repository that cannot be present in the project for the pair-programmingplugin we are using to be able to sync efficiently.

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

Any clues?

有什么线索吗?

采纳答案by Rich Seller

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 resourcesto 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.

作为参考,我发布了另一个更详细地描述如何使用链接资源的答案

回答by Gleb Varenov

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.
  1. 右键单击项目资源管理器树中的项目文件夹,然后转到“属性”。
  2. 资源 -> 资源过滤器。
  3. 根据需要为文件/文件夹添加尽可能多的排除过滤器。

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

PS 如果您的项目树没有自动更新,您可能必须在项目资源管理器窗口中输入焦点时按 F5。

回答by AlbertoPL

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.

是的,您可以在您的项目中放置自定义过滤器。在您的项目浏览器视图中,Package Explorer 选项卡的面板顶部附近应该有一个白色的向下箭头。单击它,然后转到过滤器。从那里,您可以通过选中名称过滤器模式旁边的框来指定不想检测的某些文件夹模式。在这种情况下,我会输入第 3 方库的名称。

回答by inanutshellus

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:

然后只将“goodproject”导入eclipse。如果“3rdparty”是 goodproject 的一个子目录,你可以伪造它……比如说你的 svn 项目是这样的:

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).

您可以在本地创建 project/src/ 然后只签出“main”目录,并使 eclipse 依赖于打包版本(例如,如果您的项目是 java,则指向 jar)。

回答by danilo

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

如果你想直接在.project文件中添加过滤器,这些是一些规则:

    <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 .projectfilter section for example:

例如一个.project过滤器部分:

    <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>