Subscribe to RSS

Install Eclipse Indigo with PDT on Mac OSX

Filed under: internet 3 comments

This thing I’m using for some years now for programming PHP, is Eclipse. Eclipse is a wonderful and powerful IDE—when installed and configured properly. I like to share my preferred Eclipse setup with you.

First things, first. Why should you use Eclipse for you PHP development? There are some things why I like this so much. First off, it’s completely free and you get a lot of features. Secondly, it’s platform independent. Also, it’s extendable with plugins, which I’ll cover some later on in this article.

Although some aspects of Eclipse might feel a little slow to some of you, it is nothing compared to the features it brings you. So if you haven’t tried it yet, or have tried it but didn’t quite get the feeling of it, feel free to follow my instructions and give it a(nother) shot!

Let’s begin.

Download and install Eclipse

For our installation we use the latest (3.7 when writing this article) Eclipse version—which, if you haven’t already downloaded it yet, you can download here:

http://www.eclipse.org/downloads/

Make sure you grab the Classic version of Eclipse.

Next, unpack the archived package to a location on you hard drive. I usually put this in my Applications folder. Now launch Eclipse.app—you will see the following window.

Select a location for you workspace. Please choose wisely because all files of all your PHP projects will be stored here (you don’t want to run out of MB’s, right? And of course you make sure the location is backup’ed once in a while, right?).

Press Ok. You’ll see the following screen.

Click the Go to workbench arrow-icon. Your workspace is loaded.

Download and install PDT

Help > Install New Software. Click on the Add… button. For the Name enter PDT and for the Location enter http://download.eclipse.org/tools/pdt/updates/3.0/milestones/.

Click Ok.

Now select the PHP Development Tools (PDT) All-In-One SDK and click Next.

Follow the instructions and PDT will be installed.

Configuring Eclipse

Time to do some reordering of the various tabs and panels—of-course I can’t tell you how you like it best, but this is how I like it most.

Let’s begin with opening the PHP Perspective. Go to Window > Open Perspective > Other. Select PHP and click Ok. You can now close the Java Perspective by right-clicking on it and clicking Close.

Notice that I closed the Type Hierarchy panel, moved the Outline panel from the right side to the left and moved the Task List to the bottom. Of course you can always reopen—via Window > Show View—and rearrange the tabs to your likings.

Ok, this was easy, right? Now let’s do some configurations. Open the preferences.

The following settings can be very important when you are working in a team, with other members.

Goto General > Workspace and choose the Text file encoding and New text file line delimiter. I prefer UTF-8 and Unix line endings. Make sure that all your team members are using the same settings, so you won’t run into problems later on.

An other setting I always do is Suspend all validators—while working with Eclipse I noticed it regularly felt unresponsive, this happend when it was validating project files, especially with large projects. With all validators suspended this was no longer the case.

Goto Validation and check Suppend all validators.

Another—yet personal—preference is turning off code folding. While using Eclipse I found the code folding feature pretty buggy. When copying some code it would not always get the complete function. Althought this might have been fixed in newer versions of Eclipse.

Goto PHP > Editor > Code folding and uncheck Enable folding.

There is also this thing in Eclipse that’s called Hyperlinking. When you hover over a function name while holding a Modifier Key, like ⌘ or OPTION, it will get a underline and you can click on it to navigate to the function. This always happened to me on accident while I wanted to copy some text (this probably has to do with the way how I select text, holding various modifier keys, like SHIFT or ⌘, in combination with arrow keys). Anyway I always turn the feature off. You can do this as followed.

Go to General > Editors > Text Editors > Hyperlinking and uncheck Enable on demand hyperlink style navigation.

Next, a setting that your coworkers will love you for when working with version control. When you create a new project in Eclipse it will create a few files and directories where it stores some project related settings. Normally Eclipse wants to commit these files to you version control system. Can you think of what will happen when your coworker is also using Eclipse and updates his working copy and all his settings are overwritten? Exactly—to prevent this from happening you can tell it to ignore the specific resources.

To do this go to Team > Ignored Resources and add the following patterns:

  • .settings
  • .buildpath
  • .project

Ok, we are done here for now—let’s continue.

The following setting has to do with the same resources as we just ignored for version control systems. As default Eclipse hides all resources in the PHP Explorer. This not very handy when you want to edit a .htaccess file. Let’s work on that.

Close the preferences window—if you haven’t already. Now open the contextmenu of the PHP Explorer, click on Filters….

In the following window that opens uncheck .* resources. Next, check Name filter patterns and enter the following the input box: .settings, .buildpath, .project.

Click Ok.

Ok, well done so far. Let’s continue with setting up the search. When you are developing on a project you regularly want to search—at least I want to. There are two possibilities, first you want to search inside the current document or secondly, you want to search inside the complete project/workspace. The first option works just fine in Eclipse, you press ⌘F, type your query and hit return (although you might want to check Wrap search and Incremental). The second option on the other hand works different. Try it: press CTRL + H. The following window opens. 

As you can see there are a lot of tabs. I prefer to customize this, as I don’t need all of them except for the File Search tab. Also while these tabs are active Eclipse somethings might switch to a tab based on the current context, this might confuse you when you are expecting to search through files, instead of something else. To change this you can click on Customize…

Uncheck all options except File Search and press OK. Now when you want to search, just press CTRL + H, type the query and hit return. You can also first select some text in the document and hit CTRL + H, the query will then be selected text and you only have to hit return.

Well done. You’ve now tackled most of the inconveniences that Eclipse has on default. Let’s continue with some useful plugins.

Plugins

One of the pros of using Eclipse is the support for plugins. You can install plugins as follows.

Goto HelpInstall New Software. Click on the Add… button. For the Name enter the name of the plugin and for the Location enter the url of the Update site and click Ok.

Select the items you want to install, click Next and follow the instructions. After installing a new plugin it is best to restart Eclipse.

Subclipse

Subclipse is a plugin for using SVN in Eclipse. It takes care for all SVN actions like, update, commit, checkout etc.

Update site: http://subclipse.tigris.org/update_1.6.x

One note on installing this plugin: I had to change the SVN interface in order to make it work on my OSX install.

Goto preferences > Team > SVN > Select SVNKit (Pure Java) as your Client. If it is not there, you have to install it (see the update site).

EGit

Rather using GIT instead of SVN? EGIT is a Team provider that does just that. You can browser repositories and push and pull changes from them.
You might want to check out the extensive User Guide.

Update site: http://download.eclipse.org/releases/indigo

FileSync

FileSync is a plugin that automatically syncs changed files to a preconfigured location on your harddrive. I use this plugin at work—where we work on a remote server—to sync changes to a mounted network drive.

Update site: http://andrei.gmxhome.de/eclipse/

PHP Tool Integration

This plugin adds some very useful tools to Eclipse. Tools that PHP Tool Integration includes are:

  • PHP_CodeSniffer
  • PHPUnit
  • PHP Depend
  • PHP Copy/Paste Detector

These tools can help you write better PHP code.

Update site: http://www.phpsrc.org/eclipse/pti/

AnyEdit

This plugin was brought to my attention by @pkruithof. AnyEdit adds several new tools to the context menu of text- based Eclipse editors, to output consoles, to Eclipse main menu and editor toolbar. AnyEdit contributes also Import/Export working sets wizards.

AnyEdit helps to keep your code free of any trailing whitespace.

Update site: http://andrei.gmxhome.de/eclipse/

Workflow tips

So, now that you have setup Eclipse for PHP and installed some plugins, I would like give you some final workflow tips. Actually these tips are the things I like most of working with Eclipse.

Keyboard commands

F3 Goto function declaration (I love this one so much!)
⌘D Delete current line or selection
⌘O Lookup function in document
⌘ + Option + Down Duplicate current line or selection

SVN workflow

I have taught myself a nice workflow: whenever I have made some changes to my code, and am ready to commit, I review all my changes. And it’s very easy using the Eclipse synchronize view:

Right-click the name of the project > Team > Synchronize

The synchronize view opens. It shows you all the files that are changed, compared to the revision you checked out. Now double-click the first file in the synchronize view. A compare-editor opens. This gives you a nice view of all the changes in the file. By clicking the Next difference (yellow down arrow) icon, you step through each change for each file. By reviewing every piece of changed code, you see errors, missing comments, etc. right away and you can easily fix them.

Text compare

Eclipse has a very powerful compare editor. You can compare files with each other or you can compare against a certain revision. While comparing you can make changes on the fly. I use this function quite often. To start comparing two files:

Select two files > Right-click a selected file > Compare With > Each Other.

You can now scroll through the files or jump to the next difference by pressing the Next difference icon in the top right of the editor.

Final words

I hope you found this article useful (please “like”, if so). I must admit that Eclipse has a tough learning curve, but once you get to know all the features it will become hard to code without it.

Feel free to ask me any questions or to send me suggestions. You can always contact me or leave a comment below.

 
  • Fabriciojsm

    Very, very useful. Tks bro.

  • http://twitter.com/daglees Jamil Daglees

    Nice article. I was wondering why Eclipse classic instead of PDT?

  • Anonymous

    When I wrote this article there wasn’t a PDT all-in-one version available and if I’m correct there still isn’t…