Tips and Tricks


There are so many tips and tricks for the Eclipse platform that it would not be practical to list them all here! From bookmarks to drag-and-drop (on Microsoft Windows) to hotswap debugging to simply working effectively, the list goes on. I highly recommend checking out the Eclipse Help, Help Contents menu item for various tips and tricks, which are well documented.

Shortcut Keys

The following section provides shortcut key examples using Microsoft Windows. If you are using Eclipse on a Unix/Linux-based system or Mac OS X, these keys might be slightly different. For example, on the Mac OS X, the shortcut key to invoke the File, New, Other wizard dialog box is COMMAND+N but on Microsoft Windows, it is Ctrl+N. Also, note that the functionality provided by these shortcut keys is readily available from the main menu bar or context menus.

Two shortcut key combinations I have already mentioned earlier and will reemphasize here are Ctrl+spacebar and Ctrl+1. These work almost anywhere and everywhere and provide intelligent, context-specific assistance (automatically declaring variables, for example). Use these as often as you possibly can (in the right context, of course) because they will not only save you enormous typing but also making your coding almost error-free!

The other key combinations I tend to use include the following:

  • Ctrl+M for minimizing and maximizing editors and views.

  • Ctrl+N for creating something new using one of the 100 wizards available in Eclipse.

  • Ctrl+Shift+spacebar provides hints on a method's parameters.

  • Ctrl+Shift+M to insert a missing import.

  • Ctrl+K to repeat the last find and Shift+Ctrl+K to find backward.

  • Ctrl+Shift+X converts the selected text to uppercase and Ctrl+Shift+Y to lowercase.

  • Ctrl+Shift+F formats the existing file (based on the preferences).

  • Ctrl+/ comments a single line of code.

  • Ctrl+F6, Ctrl+F7, and Ctrl+F8 enable me to cycle through editors, views, and perspectives, respectively (Ctrl+Shift+F6, Ctrl+Shift+F7, Ctrl+Shift+F8, go in the opposite direction).

  • Tab and Shift+Tab indent and unindent blocks of code, respectively.

  • F3 opens the declaration for selected item.

  • F5 refreshes a view.

Last, but certainly not least, the mother of all keys is Ctrl+Shift+L, which is a shortcut key for the Help, Key Assist menu item; this feature provides a list of shortcut keys that can be executed right from the list shown in Figure 8.47.

Figure 8.47. Help, Key Assist.


Preferences

Eclipse is a highly configurable tool. Figure 8.48 shows a screenshot of the Preferences dialog box accessible via the Windows, Preferences menu of the Eclipse workbench. There are almost too many configurable items (if that is possible); in fact, this is probably the reason there is a Filter option at the top of the Preferences window to narrow down the preference choices available.

Figure 8.48. Windows, Preferences menu.


Most views in the Eclipse SDK are also configurable via their own toolbars; some provide more configuration options than others. For example, the Package Explorer view allows us to change the layout and filter files out from the display (for example, if you want to filter out the JAR files from the listing or want to see a hierarchical view of the packages versus flat, both of which I personally like to do).

Bookmarks

Bookmarks are almost a must-have in any text editor used for development purposes. Eclipse is no different in this respect. The Edit, Add Bookmark menu item provides the capability to add bookmarks. The Basic, Bookmarks view allows us to view and go to bookmarks, as shown in Figure 8.49.

Figure 8.49. Bookmarks view.


Running External Tools and Web Browser

You can easily run external programs using the Run, External Tools menu item. You can also invoke a web browser of your choice from the Window, Web Browser menu item. For example, Figure 8.50 shows the Run dialog box; notice the various types of programs we can run and the various tabs to customize the program being run (command-line parameters, for example).

Figure 8.50. Run dialog box.


Local History

Local History allows us to compare and restore from other things from a history of this file. It can be accessed using the right-click context menu while editing a file.

Reset Perspective

If you accidentally change a predefined perspective by closing windows you didn't want to or by moving stuff around, you can always get the original state of window sizes and positions back by selecting the Window, Reset Perspective option.

Copying Elements

When we copy a line of code from one file to another, the JDT automatically copies and pastes the necessary imports required for this code to the destination source file.

Project, Clean

If you think your compiled .class files are out of sync with Eclipse or you are seeing red errors when you shouldn't, you could try running a Clean option on the wizard from the Project, Clean menu item.

Convert Delimiters

If you are used to working with files on Microsoft Windows and other Unix/Linux-based systems, you might need to convert the line delimiters. This can easily be done using the File, Convert File Delimiters To menu item.

Eclipse/JVM Startup Parameters

One other thing worth mentioning is that most times Eclipse will be fine out of the box. However, if you run into out-of-memory errors (for very large projects), you can specify extra parameters to Eclipse and to the Java VM that is running Eclipse (to increase the heap size, for example). The following is a command-line example of running Eclipse on Microsoft Windows (refer to the help documentation for more details on the parameters):

\eclipse\eclipse.exe -vm "c:\Program Files\Java\jre1.5.0_06\bin\javaw.exe"    -vmargs -Xmx512m


Refer to the Eclipse documentation for additional options; for example, the refresh option, which performs a global refresh of the workspace on startup.

Browsing Through Third-Party Source Code

You can browse (and debug) the source code of JAR files by attaching them to the source code file or directory. One way to attach to the source is by double-clicking a .class file in a JAR file from the Package Explorer view and selecting the Attach Source Code button. For example, Figure 8.51 shows how I was able to browse the JDK code after attaching the JRE lib in my Package Explorer view to C:/Program Files/Java/jdk1.5.0_06/src.zip.

Figure 8.51. Browsing third-party source code.


Eclipse Hidden Files

If you experience some completely odd problems with your Eclipse project (which I have never encountered, by the way), you could try deleting the project from Eclipse and re-creating it. In addition, Eclipse creates some dot (hidden) files and directories created by Eclipse in the project directoryfor example, .classpath, .project, and .metadata. You can try deleting these, in case there are some project-related remnants left over, and then re-create your project.



Agile Java Development with Spring, Hibernate and Eclipse
Agile Java Development with Spring, Hibernate and Eclipse
ISBN: 0672328968
EAN: 2147483647
Year: 2006
Pages: 219

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net