Eclipse
Open Resource dialog
hide .class files
Eclipse tips
Java development

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

Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms

In Eclipse IDE, the Open Resource dialog is a quick and useful feature for navigating to files within a project. However, it can become cluttered with .class files, which are typically not intended to be directly edited by developers. This article provides a guide on how to hide .class files from appearing in the Open Resource dialog in Eclipse, enhancing your productivity by reducing visual clutter.

Understanding the Open Resource Dialog

The Open Resource dialog can be accessed through several methods:

  • Ctrl+Shift+R shortcut on Windows/Linux or Cmd+Shift+R on macOS.
  • From the menu bar, navigate to Navigate -> Open Resource.

This dialog allows you to quickly locate and open files by typing part or all of the file name. Since .class files are generated bytecode files not meant for direct manipulation, hiding them can streamline your workflow.

Steps to Hide .class Files

Eclipse does not provide a direct GUI option to exclude specific file types from the Open Resource dialog, but you can use resource filters and exclusion settings:

1. Setting Up a Resource Filter

  1. Open the Package Explorer:
    • Go to Window -> Show View -> Package Explorer.
  2. Configure Filter:
    • Right-click on the project in the Package Explorer.
    • Select Properties.
    • Navigate to Resource -> Resource Filters.
  3. Add a Filter:
    • Click Add Filter....
    • Choose Exclude All as the filter type.
    • Set the Filter rule to Name matches.
    • Enter *.class in the text box to match all .class files.
  4. Apply the Filter:
    • Click OK to apply the filter.
    • Confirm by opening the Open Resource dialog and typing in a partial class name; .class files should no longer appear.

2. Using the Navigator View

If .class files still appear in other views, you can switch to using the Navigator View, which respects more advanced filtering rules:

  1. Open the Navigator View:
    • Go to Window -> Show View -> Navigator.
  2. Add Filters:
    • Use the View Menu (a small downward arrow icon).
    • Select Filters and Customization....
    • Enable *.class from the list of available filters.

3. Modifying .classpath for Exclusions

Eclipse uses a hidden .classpath file to manage build and resource settings:

  • Open the .classpath file in your project root.
  • Add an exclusion node within the classpathentry tag for your source folders:
xml
   <classpathentry kind="src" path="src">
      <exclude pattern="**/*.class"/>
   </classpathentry>
  • Save and refresh the project to apply changes.

Additional Considerations

  • Version Control: If your .classpath and other filter settings are version-controlled, ensure to communicate these changes with the team.
  • Build Configuration: Excluding .class files doesn't affect the build process since Eclipse auto-generates new .class files each time you compile.

Summary Table

MethodSteps/DescriptionAffects
Resource FilterProject properties -> Resource Filters -> Exclude all *.classPackage Explorer, Open Resource Dialog
Navigator ViewUse Navigator view and apply filtersNavigator View, Open Resource Dialog
Classpath ExclusionEdit .classpath to exclude .class filesMay require project refresh, impacts build path but not build

Implementing these methods not only helps in decluttering the Open Resource dialog but also fosters a cleaner development environment, preventing accidental edits on generated files. Considering the Eclipse environment is often used in large-scale projects, these changes can lead to substantial improvements in usability and efficiency.


Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms