Eclipse: Tips & Tricks

This page shows you how to perform a number of small, but useful tasks in Eclipse - particulary those whose commands are a bit buried in menus.

  1. Right-click anywhere in an empty area of the code editor.

  2. Choose Source > Format:

  3. Alternatively, use the keyboard shortcut: Ctrl + Shift + F

  1. In the Package Explorer window, right-click on the project to delete and choose Delete:

  2. Optional: check ON the Delete project contents on disk (cannot be undone) box to completely delete the project from the system, not just Eclipse:

  3. Hit OK to delete the project.

  1. In the code editor, select the identifier (class, method name, or variable) to find.

  2. Choose the Search menu > Occurrences in File > Identifier

  3. The Search output window displays a list of all matching occurrences in the current file:

    • Double-click an item to go directly to that occurrence.

    • Use the gold arrow buttons in the Search window's toolbar to cycle through each occurrence, or hit the grey X buttons to clear the search.
× Note:   You can also use the standard Find/Replace tool by hitting the Ctrl + F keys.
  1. In the code editor, select the identifer (class, method, variable name) or text you wish to find.

  2. Go to the Search menu > Search... (or hit the Ctrl + H keys).

  3. The Search box appears. Hit the File Search tab:

  4. If your search text does not already appear in the Containing Text box, enter the text. (Check ON Whole word for an exact word or phrase match.)

  5. Choose the Scope of your search

    • For all projects, choose Workspace

    • For just the current project, choose Selected Projects

  6. Hit the Search button.

  7. The Search output window displays a list of all matching occurrences in the current project or workspace, along with their project and package locations:

    • Double-click an item to go directly to that occurrence.

    • Use the gold arrow buttons in the Search window's toolbar to cycle through each occurrence, or hit the grey X buttons to clear the search.

  1. Go to the Search menu > Search... (or hit the Ctrl + H keys).

  2. The Search box appears. Hit the Java Search tab:

  3. In the Search String box, type the name of the search item.

  4. Choose your options for the search:

    • Search For: choose Method, Type for a class, or Field for an instance variable.

    • Limit To: choose References for all references in code, or All Occurrences to include class definitions.

    • Scope: choose Workspace for all projects, or Selected Projects for just the current project.

  5. Hit the Search button.

  6. The Search output window displays a list of all matching occurrences in the current project or workspace, along with their code paths (project > file > class > method):

    • Double-click an item to go directly to that occurrence.

    • Use the gold arrow buttons in the Search window's toolbar to cycle through each occurrence, or hit the grey X buttons to clear the search.

  1. In the Package Explorer window, right-click on the project and choose Show In > System Explorer:

  2. File Explorer or Finder opens with your project folder selected.

    × Tip:   On Windows, you can ZIP your project folder for submission by right-clicking it and choosing Send to > Compressed (zipped) folder.

The safest way to rename a package or class in your project is to change its name through the Package Explorer window, not in your code.

  1. In the Package Explorer window, right-click on the class or package and choose Refactor > Rename...:

  2. The Rename window appears. Change the name of your class/package, then hit the Finish button:

  3. If a window appears reporting problems, hit the Finish button.

    Unless you gave the class or package an invalid name, Eclipse safely changes its name in your code, as well as its file name in the Package Explorer.

  1. Right-click on the method or variable you want to rename and choose Refactor > Rename...:

  2. Eclipse highlights the name for you. Type the new name of the method/variable, then hit the Enter key:

    Unless you give the method or variable an invalid name, Eclipse safely changes all occurrences of it in your code.

If your Eclipse workspace appears "messed up" - windows missing, out of place, or collapsed - the easiest way to get things back in order is to reset the workspace's perspective.

  1. Go to the Window menu > Perspective... > Reset Perspective...:

  2. Hit the Yes button to reset the perspective to the default layout.

 

× Note:   For more help with Eclipse's settings and features, go to the Eclipse topic page.