90

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-programming plugin we are using to be able to sync efficiently.

Any clues?

Community
  • 1
  • 1
jkp
  • 78,960
  • 28
  • 103
  • 104
  • 1
    Since it's related, see here: http://www.webtrafficexchange.com/how-exclude-certain-folders-eclipse-search By right clicking a folder, clicking Properties, and checking the "Derived" box, you can actually keep your files as source files but then exclude them from file searches! – Andrew Apr 05 '18 at 13:42

6 Answers6

204

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.

Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265
Gleb Varenov
  • 2,795
  • 3
  • 18
  • 18
  • 8
    This should be the answer! This also works for C++ projects using linked folders. – void.pointer Sep 19 '14 at 15:23
  • Can you please post what will be written into the .project file? My eclipse isn't able to save that change to this file, so I will have to write it manually. – dude Jan 07 '16 at 11:04
  • 3
    Thanks for this answer, and yet, Is there any way to exclude them from build, but still let them be obervable and shown in Project Explorer? – Movsar Bekaev Apr 09 '16 at 11:56
18

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.

Community
  • 1
  • 1
Rich Seller
  • 83,208
  • 23
  • 172
  • 177
  • Rich: this was my initial approach, but the problem I found was that I couldnt make the resources relative to the project: the whole path was hard-coded. This was an issue because I need to commit the project to our SCM. Any ideas how to solve that? – jkp Jul 27 '09 at 12:32
  • I added a link to another answer that describes this in more detail. You can use a variable on the paths, if the projects are in the workspace, you can use WORKSPACE_ROOT – Rich Seller Jul 27 '09 at 12:36
  • Fantastic. I did know about the variables but I couldnt get them to work earlier. With this I should be good to go. Great answer: just what I was looking for. – jkp Jul 27 '09 at 12:38
6

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.

AlbertoPL
  • 11,479
  • 5
  • 49
  • 73
  • 1
    Alberto: thanks for the pointer, I didn't know about this at all. Only trouble is I cant find a way to exclude a whole folder at all. And as Rich points out, they will still be in the project, which will be an issue for us (I guess the plugin will try to sync them). – jkp Jul 27 '09 at 12:34
  • It seems to me that this is the only answer that is language-independent. The other instructions were not available in my Python-based project. – dbn Oct 15 '12 at 22:34
  • Eclipse indeed hides the folders, but they are still included in the build – Amir Uval Oct 14 '13 at 09:45
1

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

inanutshellus
  • 9,683
  • 9
  • 53
  • 71
1

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>
danilo
  • 7,680
  • 7
  • 43
  • 46
1

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

exclude

rupweb
  • 3,052
  • 1
  • 30
  • 57