How do I hide .class files from the Open Resource dialog in Eclipse?

I won't want to have edit any working sets. I just want a way to, across all workspaces and projects, prevent .class files from ever showing in the Open Resource Dialog. Is there a way to do this?


Solution 1:

One option is to filter derived resources. In the upper right corner of the 'Open Resource' dialog there is an arrow you can click to bring up a dropdown menu for filtering. Uncheck the 'Show Derived Resources' option, if it is checked.

If you still see '.class' files, they probably aren't being marked as derived. If they're by themselves in their own folder hierarchy you can fix this by right-clicking the root folder to edit folder properties, and check the 'Derived' checkbox. If they're mixed with your '.java' files...tough luck, you'll need to set the derived property on each '.class' file by hand.

As far as I can tell there's no way to mark class files as derived resources globally for the workspace, but I believe when you create a new Java project the 'bin' folder is marked as derived by default (if you use the default wizard settings)


Here are some screenshots from Eclipse Kepler. The first shows how to filter derived resources by unchecking 'Show Derived Resources' in the Open Resource dialog. The second shows how to set the 'Derived' property on a resource.

enter image description here

enter image description here

Solution 2:

  1. Right click on the project and select Properties enter image description here
  2. Expand Resource and click on Resource Filters
  3. Click on Add Filter... to create a new filter enter image description here
  4. On the dialog box that opens
    1. Select the Exclude all and Files radio buttons
    2. Under File and Folder Attributes enter *.class
  5. Click OK

enter image description here

To exclude an entire directory hierarchy, e.g. the target directory, select the Files and folders radio button and the All children (recursive) checkbox.

Edit

Exclude the following for a complete cleanup of Open Resource dialog

  1. Files *.class
  2. Folder bin
  3. Folder build
  4. Folder target

Without excluding all 4 it does not work.

Solution 3:

To change this behaviour and hide the “.class” files you need to do the following.

  1. Find your class output folder in the “Project explorer” window. This is usually called bin or target for Maven projects

  2. Right-click this folder and click Properties

  3. Tick the Derived checkbox (leave it UNCHECKED) and click OK

.class files will now be hidden in future.

Source: http://ayubmalik.co.uk/2011/12/hide-class-files-when-opening-a-type-or-resource-in-eclipse-ide/

Solution 4:

You can use Working sets. From the same dropdown menu on Open Resource dialog select Select working set. It opens up the working set dialogue where you can create working sets if you don't already have them.

When creating a new one, choose the type Resources and select which folders in your workspace are consider as candidates for searching or for opening resources. I have included only src and test folders and usually pom.xml's and other misc configuration files.

With the couple of large projects I'm working on it has a noticeable impact on search speed too.

Solution 5:

To solve this globally (on all projects), after pressing ctrl + shift + r, click on the top right corner of the window on the three dots button, then click on Select Working Set, tick both Java Main Source and Java Test Source and voila.