Whether you're a Mac OS X Java developer working on cross-platform Java projects, a Linux® developer switching to Mac OS X because of its UNIX®-based core, or a general Java developer looking to develop applications targeted to Mac OS X, you'll want to look at the Eclipse IDE because it provides a solution to each of these development needs. While Mac OS X provides Xcode as its primary Java development IDE, Eclipse provides a more robust cross-platform development environment, with application frameworks for reporting, database access, communications, graphics, and more, and a rich-client platform framework for building applications.
If you've used Eclipse on Linux, Eclipse on Mac OS X will be simple. Installation is a breeze. Go to the Eclipse download page (see Resources) and download the Mac OS X version of Eclipse IDE for Java Developers. Download a gzipped .tar file, which you must expand into a folder named Eclipse. Using the Finder, drag this folder into your Applications folder. To launch Eclipse, simply double-click on the Eclipse application.
If you have used Eclipse on another platform, you'll see a familiar window. If you use Xcode (the development IDE included with Mac OS X) for your development, your projects are typically saved in your home directory. With Eclipse, your workspace is automatically created in your Documents directory, and, by default, all your projects are saved to this location.
Say you have Java projects you created in Xcode that you want to migrate to Eclipse. Fortunately, migrating your existing applications to Eclipse is quite easy. To migrate an existing application to Eclipse:
- In Eclipse, create a new Java project.
- From the File menu, choose New Project.
- In the New Project window, select the Java Project wizard (Figure 1). Click Next.
Figure 1. Select the Java Project wizard
- Name your new project, then select Create project from existing source, as
Figure 2. Create a Java project from an existing source
- Click Browse to the locate the directory in which your existing project resides, usually a location in your Home directory.
- Click Finish or click Next to continue the configuration of your new project. By default, Eclipse automatically compiles all the .java files in your project directory.
- To ensure compilation, choose Project > Build Automatically. When Eclipse
compiles your application, any errors or problems appear in the Problems view at the
bottom of the Eclipse IDE window, as shown in Figure 3. If the Problems tab is not
displayed, choose Window > Show View > Problems.
Figure 3. The Eclipse workspace
Note: You may see several warnings if you created your application using an existing Xcode application template. In this example, the project imported in Figure 3 was based on the Xcode Swing template project, so there are several warnings indicating that a class does not declare a static final
serialVersionUID, which is only important if you plan to serialize these classes. You may find these warnings annoying, but there is a simple way to remove them from the Problems view.
- Choose Eclipse > Preferences to display the Preferences window.
- In the left pane, expand Java, expand Compiler, then click Errors/Warnings.
- In the right pane, expand Potential programming problems, as shown below.
Figure 4. Remove warnings from the Problems view
- Change the Serializable class without serialVersionUID option from Warning to Ignore.
- Click OK to save your new preferences. You will be prompted to rebuild your application. When completed, these warnings will be removed from the Problems view.
If you're building a Swing-based application that uses menus, when you run your application, the menu will be displayed as part of the application window, rather than at the top of the screen, as typical with Mac OS X applications. By default, Xcode adds arguments to the virtual machine to ensure that the top of the screen menu is displayed. However, with Eclipse, you must manually add this argument. When you choose Run > Run menu, the Run window appears. Click the Arguments tab, as shown below.
Figure 5. The Run window
In the VM arguments box, type
-Dapple.laf.useScreenMenuBar=true. Now, your Swing application menu
appears at the top of the window, instead of your application window, and will look like
a normal Mac OS X application. If your Java application is Standard Widget Toolkit
(SWT)-based, this argument is not required.
If you're an experienced Mac user, you may find that a few of the Ctrl+key combinations Eclipse uses aren't what you expect (or like). For example, if you're a frequent Xcode or TextEdit user, you'll find that the shortcut keys for Find Next and Find Previous are mapped to Command+K and Command+Shift+K, respectively, instead of the Command+G and Command+Shift+G you're familiar with. Fortunately, Eclipse provides a mechanism to edit your key bindings — the Ctrl+key combinations you use to accomplish a specific task — to your liking. To modify the key bindings, choose Eclipse > Preferences to display the Preferences window. In the left pane, expand General, expand Editors, then click Keys to display the View, as shown below.
Figure 6. Modify key bindings
To modify the key bindings for a function, select the command from the list (for example, Find Next. Click Edit to display the Modify tab, shown in Figure 7. In the Name box beneath Key Sequence, delete the current key combination and simply hold down the combination of keys with which you want to replace this function — in this case, Command+G. Click Add to save your new key combination.
Figure 7. Modify Command+key sequences
Note: Eclipse will keep the original key binding for the selected function, as well. If you want to delete the original key binding, select it from the Assignments list beneath Command, then click Remove.
Click View to return to the key bindings. You can modify the key bindings for text editing, navigation, refactoring, run/debug, search, and source functions to your liking.
If you're going to build complex applications in Eclipse on Mac OS X, you want to take advantage of version control. Eclipse provides integration with CVS, an open source system for tracking different versions of your application's source code. Recall that at its core, Mac OS X is based on a flavor of Berkeley Software Distribution (BSD) Linux, so it comes bundled with a working, installed version of CVS.
The Apple Developer Connection Web site (see Resources) provides an article that can guide you through the configuration of CVS on Mac OS X, so I won't go through that process here. Instead, this article focuses on the CVS command-line options. To integrate CVS with Eclipse, you must do a bit of tinkering.
First, you must enable Remote Login functionality on your computer. Be aware that enabling remote login allows anyone with your username and password to access your computer, so you'll be doing this at your own risk.
To enable remote login on Mac OS X:
- Click the Apple icon, then click System Preferences.
- In the System Preferences window, click the Sharing icon.
- Select Sharing to display the Sharing window.
- Select the Remote Login checkbox, shown in Figure 8, and the service will automatically start.
Figure 8. Enable Remote Login functionality
- Close the Systems Preferences window to save your changes.
To verify that Remote Login has been enabled, use the Terminal application, which
provides you with bash shell access. At the command prompt, type
ssh localhost. Type your password, then exit to close your remote login session.
You can now add your Eclipse projects to the local CVS tree. Here's how:
- From the Package View, right-click your project folder, then click Team > Share
Project. The Share Project window appears, as shown below.
Figure 9. The Share Project window
- In the Host box, type
localhost. If you followed the CVS configuration tutorial, you'll type
/usr/local/cvsrepfor the repository path.
- Type your username and password beneath Authentication.
- For the connection type, select extssh, then click Next.
- In the Enter Module Name window, select Use project name as module name,
as shown in Figure 10, then click Next.
Figure 10. Name the project
Eclipse connects to the CVS server and creates the module. When that process is
complete, Eclipse confirms check-in of the files into the repository. Click
Finish to display the Commit Wizard, which prompts you for a log entry. If this
is the first time you're checking in your project files, you can type something like
Project Start Check-in or
Check-in. You're now able to use CVS to manage versioning within your application.
Eclipse uses the local character set of the operating system when editing source files. By default, Eclipse on Mac OS X uses the MacRoman character set. If you're working with Eclipse on a cross-platform project, it's better to use UTF-8 character encoding. To specify this encoding for all files in a project, right-click the project in the Package Explorer view, then click Properties. Beneath Text file encoding, select Other, then select UTF-8 from the list, as shown below.
Figure 11. Set the character encoding
Finally, there are a few other small things you can do to help maximize Eclipse performance on Mac OS X. First, you can specify the minimum and maximum heap space that the Java Virtual Machine (JVM) allocates. By default, Eclipse allocates between 40 and 256 MB of memory for the heap. To modify the amount of memory allocated, you must modify the eclipse.ini file. To access eclipse.ini, right-click the Eclipse application icon, then click Show Package Contents to open a new Finder window displaying a Contents folder. Open the Contents folder, and then open the MacOS folder, in which the eclipse.ini file resides.
Figure 12. The eclipse.ini file in TextEdit
Modify the value after the
-Xms option to change the minimum
heap space and the value after the
-Xmx option to change the
maximum heap space. For example, to use a heap size between 64 and 512 MB, change the
If you have Eclipse open, you must close and reopen Eclipse for these new options to take effect.
You can also experience performance gains by turning off automatic Content Assist, which provides a list of suggested completions for partially entered strings. From the Eclipse Preferences window, in the left pane, expand Java, expand Editor, then click Content Assist. Then, clear the Enable Auto Activation checkbox. You can still invoke Content Assist manually by using the Shift+Space key combination.
Disabling automatic folding also results in performance gains in large projects. To disable Automatic Folding, from the Eclipse Preferences window, in the left pane, expand Java, expand Editor, then click Folding, then clear the Enable Folding checkbox.
Mac OS X provides a familiar development environment for developers experienced with Linux. Using the techniques outlined in this article, you can maximize your Eclipse development experience on the Mac platform.
Control with CVS on Mac OS X" (Apple Developer Connection) is a step-by-step guide to configuring CVS on Mac OS X.
Check out the "Recommended Eclipse reading list."
Browse all the Eclipse content on developerWorks.
New to Eclipse? Read the developerWorks article "Get started with Eclipse Platform" to learn its origin and architecture, and how to extend Eclipse with plug-ins.
Expand your Eclipse skills by checking out IBM developerWorks' Eclipse project resources.
To listen to interesting interviews and discussions for software developers, check out
check out developerWorks podcasts.
For an introduction to the Eclipse platform, see "Getting started with the Eclipse Platform."
Stay current with developerWorks' Technical events and webcasts.
Watch and learn about IBM and open source technologies and product functions with the
no-cost developerWorks On demand demos.
Check out upcoming conferences, trade shows, webcasts, and other Events around the world that are of interest to IBM open source developers.
Visit the developerWorks Open source zone for extensive how-to information, tools, and project updates to help you develop with open source technologies and use them with IBM's products.
Get products and technologies
Check out the latest Eclipse technology downloads at IBM alphaWorks.
Download Eclipse Platform and other projects from the Eclipse Foundation.
Download IBM product evaluation versions, and get your hands on application development tools and middleware products from DB2®, Lotus®, Rational®, Tivoli®, and WebSphere®.
Innovate your next open source development project with IBM trial software, available for download or on DVD.
The Eclipse Platform newsgroups should be your first stop to discuss questions regarding Eclipse. (Selecting this will launch your default Usenet news reader application and open eclipse.platform.)
The Eclipse newsgroups has many resources for people interested in using and extending Eclipse.
Participate in developerWorks blogs and get involved in the developerWorks community.
John Fronckowiak is president and founder of IDC Consulting Inc. and also a Clinical Assistant Professor in Information Systems at Medaille College, at the School of Adult and Graduate Education. He is the author of several books and articles about Web application development, programming, database design and development, and networking. You can reach John at firstname.lastname@example.org.