Jan 11, 2010

Eclipse eclipse logois a powerful open source IDE built on Java that has been around since 2001 and has become quite useful tool for PHP development, including Drupal. This post is meant to give some rationale on why to use this platform for Drupal development and get you oriented as soon as possible. With Eclipse, there is definitely a learning curve, but if you give it a chance I’ll think you’ll find it an indispensable resource for your toolbox.

Why Eclipse / PHP Development Tools (PDT)?
  • Open source – forever free
  • Multi-platform, have same experience on MacOS/Windows!
  • Code assist, including Drupal API functions, HTML markup and CSS attributes!
    • F3 to go right to function’s declaration!
  • Great SVN/CVS integration
    • Easily see which files have been modified, which files are new, committing/updating is easy
  • Function outline
    • Makes it easy to find functions defined in a module
  • IDEs keep projects organized
  • PHP syntax validation, easily find syntax errors in the file itself and PHP outline
 
Steps to Getting Up And Running

NOTE: I am running Eclipse on a Windows 7 box with XAMPP as my LAMP stack, but the instructions are basically the same for MacOS.
 
  1. Download and install Eclipse PDT
  2. Install Subclipse from Eclipse
  3. Configure Eclipse – this is where it gets tricky!
  4. Create a test project and try it out yourself
 
1.       Download and install Eclipse PDT
 
Eclipse is easier than ever with the PDT platform. Go to the Eclipse homepage and you will see a link for Eclipse for PHP Developers. What’s different about installing Eclipse is that it doesn’t have an install dialog, basically all you do is drop the eclipse folder anywhere on your machine, in Windows I put it in ‘Program Files’ and create a shortcut myself. When you first launch Eclipse, it will ask for your workspace, usually I recommend pointing to your www folder or htdocs.
 
2.       Install Subclipse from Eclipse
 
You will also probably want SVN integration and for that you will need to install Subclipse, view the installation instructions here. I will not go into full detail here but an important note is that Eclipse allows you to install plugins from the IDE itself, via the ‘Install New Software…’ menu item from the help screen. Basically this involves giving Eclipse the download URL and selecting what to install. There is an optional driver, I think for Java I would ignore that - as it usually fails when I try to install Subclipse and it’s not needed.
 
eclipse subsclipse screenshot
 
3.       Configure Eclipse – this is where it gets tricky!
 
Almost all of the instructions below involve changing settings under the Window - Preferences menu item. If you spend any time with Eclipse, you will need to get very familiar with the preferences dialog. Some of these instructions are optional but I strongly recommend all of them for Drupal development.
 
  • Select a workspace
    • This is the first thing you are prompted when launching Eclipse, I select the XAMPP htdocs folder (or WAMP www, etc) and make it always start with this workspace
  • Select PHP perspective (if not already selected)
    • If you ever don’t see PHP explorer you might be in the wrong perspective, in which case select Window..Open Perspective..PHP
  • Adjust PHP settings
    • In preferences, under PHP..PHP Executables you will need to add the paths to your executable path and php ini path.
  • Turn off validation
    • In preferences, under validation I would uncheck all the validation because I find it to be too strict. If you have PHP errors those will still be shown in the PHP explorer.
  • Turn off ‘Enable auto activation’
    • ‘Auto activation’ will trigger code assist automatically and can REALLY slow things down, my advice is to disable this option and use ctrl+space to trigger auto assist as needed. You shouldn’t have to do this for PHP but for CSS/HTML/JavaScript.
    • In preferences, under Web..JavaScript..Editor..Content Assist unclick ‘Enable auto activation’
    • In preferences, under Web..HTML Files..Editor unclick ‘Automatically make suggestions’
  • Adjust Subclipse settings
    • In preferences, under Team..SVN I wold change the ‘SVN interface’ client to ‘SVNKit’, this is not selected by default but I cannot get SVN to work with the default client.
    • In preferences, under Team..SVN..Menu Icons I would use ‘Subversive’
  • Convert tabs to spaces
    • Use 2 spaces for tabs according to Drupal coding standards
    • In preferences, under General..Editor..Text Editors change ‘Displayed tab width’ to 2
    • In preferences, under PHP..Code Style..Formatter change to spaces/2.
    • In preferences, under Web..CSS Files..Editor change to spaces/2.
    • In preferences, under Web..HTML Files..Editor change to spaces/2.
    • In preferences, under XML..XML Files..Editor change to spaces/2.
  • Add .module to PHP editor types
    • In preferences, under General..Content Types double click ‘Text’ and find the ‘PHP Content Type’. Add ‘.module’ and click OK, you will probably need to restart Eclipse for this change to take effect.
  • Enable line numbers
    • This really helps, in preferences under General..Editors..Text Editors click ‘Show line numbers’
  • Add PHP support
    • Sometimes a project does not automatically have PHP support, in which case you can right click a project in the PHP Explorer and under Configure select ‘Add PHP Support’
      • This sometimes occurs when you add a pre-existing project to the Eclipse workspace

 

eclipse preferences dialog screenshot

 
4.       Create a test project and try it out yourself
 
Right click in the PHP Explorer on the left side of the screen and click New..PHP Project to add a php project and start playing around! Also if you work off of SVN like we do you will normally add a new project by right clicking and selecting ‘Import..’, then select SVN and following that dialog to import an SVN project into your workspace.
 
In summary
 
If you have done any tire-kicking with Eclipse before but had trouble I hope the step 3 breakdown of configration settings helped. It took me a long time to find all these settings so I strongly suggest you read through that step before playing around with Eclipse.
 
Part of the problem with Eclipse is that the documentation is scattered and so it can be really difficult to get up and running quickly. I have talked to a number of people who tried Eclipse in the past and gave up. That being said, I implore you to try again because I believe you’ll find it a powerful platform once you get past the initial set of “secret handshakes.” Features like SVN integration, code assist and real-time PHP syntax validation have made Eclipse my favorite platform for Drupal development.
 
Additional References/Links:
 

 
Feedback? Comment below or reply at http://twitter.com/drupalninja.


Netbeans is great!
Jan, 28 2010 - Amir Reavis-Bey

I am also a fan of Netbeans. I tried Eclipse and although I liked it, I find Netbeans much easier to use and setup as well. Once I got debugging to work on Eclipse I started having performance issues and haven't looked back.


Using with other languages
Jan, 28 2010 - Jeremy Dost

Great article! One thing that's kept me with eclipse is that it I can use it for development in other languages - specifically ruby and flex and there's good community support and resources out there for doing that. I've not tried netbeans before. Does anyone else use netbeans for ruby and/or flex development?


Eclipse, Aptana, Java Tools & Speed
Jan, 26 2010 - Donny Nyamweya
Java IDEs such as Eclipse and Aptana (just eclipse with some better looks) are awfully slow. I first tested Aptana two years ago and set it aside thinking that the 2GB on my MacBook was the root of the problem. However, I tested the IDE as well as Eclipse last year (by then I had 4GB if RAM), and the application was still slow. At times, it required me to multi-task so that I can glance at the other screen while waiting for things to be ready. I am not being paid by Panic Inc., but I have been using Coda for the last 18 months (yes, it costs about $90), and it is simple, powerful, extensible, and agile. The application (or IDE if you think it qualifies) melts and you just see yourself working on your code, moving files, checking into SVN, doing DIFF, chatting and comparing code on your LAN, searching files on your Pac, or on the Server via SSH... To make a long story short, Eclipse-based tools and Java tools in general are not known for speed (out of the box) and one often has to have an MSc. in tweaking them to get the thing running --

Drupal plugin for Eclipse IDE
Jan, 13 2010 - Chris Charlton
For the new year I released a Drupal plugin for Eclipse IDE that adds the necessary Drupal file extensions to PDT (required). http://groups.drupal.org/node/39938 For Dreamweaver fans, I have Drupal extensions available at http://xtnd.us

I tried Eclipse, I tried
Jan, 13 2010 - Drupal tutorials
I tried Eclipse, I tried Aptana...well...Java based IDE isn't best choice for an impatient person, after playing with phpDesigner(which is pretty fast), I stayed with Komodo...has every feature Eclipse offers + more and is pretty swift.

Netbeans + Drupal
Jan, 13 2010 - Brent Ratliff
Jay, Thanks for the config settings. I've been playing a little with Netbeans trying to decide which IDE to use for theme development. Anyone have experience with the Drupal 6 plugin for Netbeans? Jay, I'd be interested to get your opinion of it. http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=10859.

I tried netbeans yesterday
Jan, 13 2010 - Jay Callicott
I tried out netbeans yesterday and I don't think for someone who likes the slickness of eclipse would want to switchover to netbeans, maybe if you don't have an IDE you like you might prefer netbeans bc it's easier to setup. I had to install an extra subversion plugin which wasn't too bad and I checked out an svn project. I just really like the eclipse interface so I suppose from my vantage point I just wasn't all that impressed. I tried out auto complete and it looked pretty nice, comparable to eclipse and other IDE's. One thing that's bothering me with eclipse right now is that the auto-complete is crashing all of a sudden, that never has happened before. As far as netbeans being supposedly 'lighter', my experience was that it still runs on java and the javaw executable was 250mb on my machine on launch so I don't know that netbeans is any less memory hungary than eclipse. Eclipse eats memory but that's less and less a problem for me as I upgrade laptops. I'm running a 4gig memory windows 7 box and I can run eclipse w/memory hungry firefox and a bunch of other programs and everything runs just lovely. So netbeans isn't bad but I don't think it would make any eclipse lover like myself instantly switch over to netbeans any time soon.

great article
Jan, 12 2010 - Brian Stevenson
I just had a client come to me today asking if I could connect to their SVN to do some development. Now I know Subclipse is the way to go. Thanks for the write up! Peace, Brian

Yes subclipse rocks
Jan, 13 2010 - Jay Callicott
Subclipse is awesome bc it is so integrated w/everything. I've used command line svn and tortoise in the past on occasion and you just don't get the birds eye view of all your modified/committed files in the navigation that you get when svn is integrated w/the IDE. Just remember the settings for subclipse are important, I had to play w/it a while before I found settings that would work so that section of my article is important.

xdebug on eclipse
Jan, 12 2010 - whatdoesitwant
Xdebug is supposed to run on eclipse as well. See http://www.techiedesi.com/post/229-setup-xdebug-and-php5-with-eclipse-34-to-debug-your-php-website-at-runtime and http://drupal.org/node/260854 If you do theming, set aside your preconceptions and add aptana, it's lovely. If your system cán handle it without drag, auto activation is awesome.

++ Netbeans
Jan, 12 2010 - dalin
I did Eclipse for 2 years but I was continually frustrated with the poor performance and complicated configuration. I finally found the time to try Netbeans and after 10 minutes with it I sweared never to return to Eclipse. Netbeans is elegantly simple, very fast, and no need for secret handshakes.

Another vote for Netbeans
Jan, 12 2010 - blair
I have used a few IDE's, including Eclipse and Aptana and have to agree with David Herron, Netbeans provides a far better experience with a similar level of power. I have only used Netbeans for a few days and already I totally love it. Eclipse was always a nightmere to get working right and in the end it became unworkable when I was debugging - it just totally froze and I couldn't get it back. I had a similar experience with Aptana when I loaded a big project. Even uninstalling and reinstalling wouldn't bring it back to life. No such trouble with Netbeans. It is a pleasure to use.

Adding the Zend Debugger
Jan, 11 2010 - Bill Judd
After installing Eclipse PDT, I also download the Zend Debugger extension binaries (http://downloads.zend.com/pdt/server-debugger/) for the development platform I am setting up. I do Drupal development on both Macs and PCs; I download the most-recent "cygwin" file for my PC and the "darwin" for my Mac. After expanding the downloaded archive file, follow the steps in the README file to set up the debugger. Step 3 of the README says: 3. Add the following lines to your php.ini file: zend_debugger.allow_hosts= zend_debugger.expose_remotely=always In place of "", substitute 127.0.0.1/32 After completing all 5 steps of the README, restart Apache. Within the Eclipse PDT, select Preferences/PHP/Debug/Installed Debuggers. In the "Installed Debuggers", select Zend Debugger and click the "Configure" button. Modify the contents of the "Client Host/IP" text box; make the IP address be "127.0.0.1". Click "Ok" to close the "Zend Debugger Settings" dialog. Click "Ok" to close "Preferences". Back in the main window, select "Debug Configurations..." in the Debug drop-down. Select "Zend Debugger" in the Server debugger drop-down list, and select "Default PHP Web Server" in the PHP Server drop-down list. If you have completed all configuration steps correctly, clicking on the "Test Debugger" button will display "Success!" in the Test Debugger Server dialog. You will now be able to set breakpoints and single-step through any of the PHP code in your site. Happy debugging!

Netbeans
Jan, 11 2010 - David Herron
I prefer using netbeans over eclipse - my experience with eclipse is that it's got a horrendous configuration for adding plugins. On the other hand netbeans is trivially easy to configure. You can get PHP support direct from the downloads on the netbeans site or you can easily add PHP support in afterwards using the standard mechanism for accessing netbeans modules. Netbeans configuration is similar to the steps you outlined above (e.g. setting up coding standards). Netbeans can do debugging of remote PHP instances using XDebug. The only deficiency is the "hook" aspect of Drupal coding practice. I don't see from the above that eclipse is any better. That is when Drupal code invokes a hook the the function names invoked are determined by gluing together strings passed into module_invoke. There's no way for the IDE to work out which functions will be called from that and hence it is thus difficult to properly traverse the source code between the point where the hook is invoked and the place(s) where the invocation lands. But this is because Drupal's coding practice is obfuscatory.

i will try netbeans
Jan, 12 2010 - Jay Callicott
Well seeing all this great feedback for netbeans makes me want to try it out again. I played with it a long time ago when I was messing around w/java and it seemed like an OK IDE , I didn't realize it had good PHP support. I really love eclipse so it will take a lot for me to switch, but I will certainly give it a try.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.