Configuring Eclipse

Last modified: September 23, 2009 - 02:55

Configuring Eclipse

Eclipse is an open-source integrated development environment (IDE) that is used to develop systems in many languages and on many platforms. Many use it to develop Drupal systems. Eclipse has many add-ons and extensions called "plug-ins" or "packages." There are also separate IDEs that have been created that are based on Eclipse. There are some simple preferences to set within an Eclipse IDE so that Drupal will work and so that you can commit correctly encoded files to the Drupal CVS repository.

In general, you need to make sure that your Eclipse environment will:

  • adhere to Drupal coding standards,
  • use syntax highlighting (very, very helpful in any coding language!)
  • recognize Drupal files as PHP code,
  • make sure that spaces are used instead of tabs, and
  • make sure that the files have the right encoding (Unix) so they can be committed to the Drupal CVS repository.

In addition, there are plug-ins and packages that can help you with CVS, debugging (remote), and lots more.

There are different settings for different packages, plug-ins, and Eclipse-based IDEs. Look below to find the plug-in(s), package(s) and/or IDE you have and the changes you'll need to make. Note that you need to make changes for each of the packages and plug-ins. (If you are not sure about what packages or plug-ins you have in your Eclipse IDE, use the Eclipse help system to find out how to list everything you have installed.)

Contents:

If there is an Eclipse package, plug-in, or environment that isn't covered here and you have configuration info, please edit this page and add your information. Please do include the version number for the package, plug-in, or environment since settings may differ from version to version. Please do not include images because doing so will lock this page.

If you have a question about an Eclipse package, plug-in, or environment and cannot find answers here or in the links provided below, please search the forums and groups. If you don't find an answer, add your question to the comments below so others can investigate and help. If you do find an answer, please edit this page and add the info.

 

PHP Development Tools (PDT) (package)

This is the official Eclipse project developed by Zend at http://www.eclipse.org/pdt/.

  1. Make sure Drupal file types are recognized as PHP files:

    For PDT version 2.1.1: Under Window -> Preferences (Eclipse
    -> Preferences
    on Mac) menu:

    • Expand the left-hand menu to General -> Content Types. Under Content types on the right, click Text -> PHP Content Type. Add the *.engine, *.theme, *.install, *.inc, *.module and *.test file
      types so that these files will be recognized as PHP.
  2. Make sure the file encoding and characters are Unix friendly so that any code and be committed back in to the Drupal CVS:

    For PDT version 2.1.1: Under Window -> Preferences (Eclipse
    -> Preferences
    on Mac) menu:

    • In the left-hand menu click on General -> Editors -> Text
      Editors
      : Check Text file encoding and select
      Other :
             UTF-8
      . Check New text file line delimiter and select
      Other:
             Unix
  3. Ensure that spaces are used instead of tabs:

    For PDT version 2.1.1: Under Window -> Preferences (Eclipse
    -> Preferences
    on Mac) menu:

    • In the left-hand menu click on General -> Editors -> Text
      Editors
      : Check Insert spaces for tabs.
    • In the left-hand menu click on PHP -> Code Style ->
      Formatter
      : Set Tab policy: Spaces. Set Indentation size to 2.

For those using Smarty as a template engine, here's info on Smarty Highlighting in PDT.

Here are some Eclipse PDT templates.

Back to Top

PHPeclipse (package)

The community developer project is at http://www.phpeclipse.net/.

  1. Make sure Drupal file types are recognized as PHP files:

    For version ?: Under Window -> Preferences (Eclipse
    -> Preferences
    on Mac) menu:

    • Expand the left-hand menu to General -> Content Types.   Under Content types on the right, click Text -> PHP Content
      Type
      . Add the <em>*.engine</em>, <em>*.theme</em>, <em>*.install</em>, <em>*.inc</em>, <em>*.module</em> and *.test file
      types.
  2. Ensure that spaces are used instead of tabs:

    For version ?: Under Window -> Preferences (Eclipse
    -> Preferences
    on Mac) menu:

    • In the left-hand menu click on General -> Editors -> Text
      Editors
      : Check Insert spaces for tabs.
    • In the left-hand menu click on PHPeclipse -> PHP:
      • In the Typing tab, make sure the Insert Spaces for Tab setting is
        checked.
      • In the Appearance tab,
        leave the Displayed tab width at 4, so it is easier to spot if any
        actual tabs have snuck in.
    • In the left-hand menu click on PHPeclipse -> PHP ->
      Formatter
      :

      • In the Style tab, enter 2 for Number of
        spaces representing a tab
        .
      • Compact Assignment and Indentation is represented by a tab should both be
        unchecked.
  3. Make sure the file encoding and characters are Unix friendly so that any code and be committed back in to the Drupal CVS:

    For version ?: Under Window -> Preferences (Eclipse
    -> Preferences
    on Mac) menu:

    • In the left-hand menu click on General -> Editors -> Text
      Editors
      :

      • Check Text file encoding and select
        Other :
                   UTF-8
      • Check New text file line delimiter and select
        Other:
                   Unix.

Back to Top

Eclipse Web Tools Platform (WTP) project

The WTP project extends Eclipse to is package with editors, profilers, tools to for developing applications for the web and Java EE.

  1. Ensure that spaces are used instead of tabs:

    For version ?: Under Window -> Preferences (Eclipse -> Preferences on Mac) menu:

    • Expand the left-hand menu to Web -> CSS Files -> Editor: Select Indent using spaces. Set Indentation size to 2.
    • Expand the left-hand menu to General-> Editors -> Text
      Editors
      : Select Displayed tab width. Set Indentation size to 2.
    • Expand the left-hand menu to Web -> HTML Files -> Editor: Select Indent using spaces. Set Indentation size to 2.
    • Expand the left-hand menu to XML -> XML Files -> Editor: Select Indent using spaces. Set Indentation size to 2.
  2. If you use XTemplate: expand the left-hand menu to General -> Content Types -> Text -> HTML:

    • Add the *.xtmpl file type.

Back to Top

Aptana (Eclipse-based IDE)

This is an Eclipse based IDE (or Eclipse extension) for editing PHP, CSS, xHTML,
JavaScript and the like.

  1. Ensure that spaces are used instead of tabs:

    For version ?: Under Window -> Preferences (Eclipse -> Preferences on Mac) menu:

    • Expand the left-hand menu to General -> Editors -> Text Editor: Enter 2 for Displayed tab width.
    • Expand the left-hand menu to Aptana -> Editors: Under Tab Insertion on the right, click
      Use
             Spaces.
      If current width is not set to 2, click the edit link.

Using Aptana on OS X: shunting wrote how he installed Aptana, and his experience using it for remote debugging.

Back to Top

CVS (plug-in)

This is a plug-in for working with CVS systems from within an Eclipse IDE. This plug-in generally is included in the core Eclipse IDE installation. The following settings
ensure that if you upload files to Drupal.org or create patches to upload, the uploads are in the standardized format (UTF-8, Unix line endings, and CVS -kkv
mode).

  1. Make sure the file encoding and characters are Unix friendly so that any code and be committed back in to the Drupal CVS:

    For version ?: Under Window -> Preferences (Eclipse
    -> Preferences
    on Mac) menu:

    • Expand the left-hand menu to General -> Workspace. Set Text file encoding to UTF-8. Set New text file line delimiter to Unix.
    • Expand the left-hand menu to Team -> CVS:
      • Click on the Files and Folders tab.
      • Set the Default text mode drop down to
        ASCII with keyword
                   expansion (-kkv)
        .
      • Disable the
        Convert text files to use
                   platform line ending
        checkbox.

Back to Top

jQuery (package)

Be sure that you have an unpacked version of jQuery installed in your Eclipse IDE. According to dman: If you want to be debugging jquery, you need to be using the unpacked version (available at the jquery site)
Yes, Eclipse fails to load the compressed version (it freezes for 3 minutes or more) due to it all being one long line. It wouldn't be much help for reading anyway, as the packed version is almost unreadable.
Replace your jquery.js with the unpacked and carry on!

Back to Top

XDebug (plug-in)

XDebug is a debugger and profiler for PHP. The XDebug plug-in for PHPEclipse can be used to debug Drupal remotely or locally.

http://www.phpeclipse.com/wiki/Howto/XDebugAndPHPEclipse describes how to install XDebug for PHPEclipse.

Be sure to do the following: (Not clear which version of XDebug this applies to.)

  • On the XDebug Remote Script configuration, on the Main page you can leave the Remote Location blank, and on the Pathmap page set the Remote path as / to map it to a physical Apache doc root.
  • Make sure also to disable DBG debugging by deleting the net.sourceforge.phpeclipse.debug.core and net.sourceforge.phpeclipse.debug.ui jars because the two debuggers cannot coexist at present.

To use XDebug.dll with Eclipse PDT on Windows: http://www.102degrees.com/blog/2008/05/20/xdebug-and-eclipse-pdt-on-windows-from-start-to-finish/

Back to Top

Additional Documentation and Resources:

Back to Top

 

TODO:

Additional things that might be useful to add here (from http://drupal.org/node/207338 ):

  • Indentation, <?php tags in line with the drupal Coding Standards.
  • CVS: roll a patch and apply a patch.

just curious what is best

armyofda12mnkeys - October 27, 2008 - 00:23

just curious what is best way to setup drupal with eclipse workspace-wise?

my usual setup is htdocs/site1, htdocs/site2 htdocs/site3 in apache,
in apache conf file, i have virtual hosting setup so for example htdocs/site1 is associated with alias site1, aka http://site1. etc (i guess even doing this with site1.com will work too but it could get confusing versus your live site).
and then in windows hosts file, have it setup so site1, site2, site3 are pointing to localhost.

should eclipses workspace be in your home|mydocuments directory just so store settings, and each site folder its own Project, so like htdocs/site1 is a project directory and mydocuments/workspace is your settings.

i saw some tutorials where the workspace is actually htdocs/site1, and some where mydocuments/workspace is the workspace and it seems like they publish to a directory htdocs/site1?

right now i think im going to go with keeping workspace outside of htdocs, unless anyone has a good reason otherwise.

EDIT: i think theres a couple approaches
* like above have the workspace outside of web directory, but when starting a new project, dont 'Use Default' for default workspace directory.
so actually point to the drupal directory/project on localhost. and eclipse settings will still be in default workspace using.
I would still use vhosting setup so u can reach http://site4 like the below settings only difference is, /site4 is in htdocs and >Directory not needed if using default apache settings for access.

* have the workspace separate but setup in apache to reach it, like
apache conf file

<VirtualHost *:80>
DocumentRoot "C:\Documents and Settings\ach\My Documents\workspace\site4"
ServerName site4:80
ErrorLog logs/site4_error.log
CustomLog logs/site4_access.log common
<Directory "C:\Documents and Settings\ach\My Documents\workspace\site4">
Options Indexes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

hosts file:
127.0.0.1 site4
and setup eclipses debug options so setup a PHP Server to be http://site4
* same setup as above but just make the workspace the drupal install site4 inside of htdocs, and configure vhosting.
* have it seperate and use eclipse plugin like esFTP to sync local workspace to a site if not testing locally

Errors after creating new PHP project

yymoto2 - April 14, 2009 - 12:17

Hi, I'm new to eclipse and with minimal understanding of programming, trying to setup a proper IDE development environment and learn.

I'm on Window XP, using Drupal 6.10, xampp, successfully installed PDT2.0 + Zend Debugger v5.2.15 but encounter issues when trying to create a new project. Here's what I did:

1) File > New > PHP Project
2) Inside 'PHP Project' box, I do the following:
- 'Create content from existing source' where I point to "e:\xampp\htdocs\drupal6.10"
- Enable javascript support
3) click 'Finish'
4) File > Import > General > File System > From Directory "e:\xampp\htdocs\drupal6.10" > Into Folder "my_new_project"
5) Finish

The entire folder get imported but it turns out to have a long list of error present at the 'Problems' tab. Following are the errors (sorry I don't know how to attach a screencap of error page):
1) Error Type = 'JavaScript problem'
2) With the 'Description' such as: "cannot be resolve to a type", "$ cannot be resolved", "blocks cannot be resolved", "cannot make a static reference...."
3) Practically involves every single ".js" file.

May I know where I did wrong or missing out any steps? Is my approach to add a Drupal project correct? Can somebody point me to the right direction?

Thanks for the help :)

Re: Errors after creating new PHP project

whatdoesitwant - June 15, 2009 - 11:35

Hi yymoto2,

I saw your question just now.
I do not think your step 4 and 5 are necessary.

  • You either create your project from an existing source (step 1-2-3) and finish: now all your drupal6.10 directory content becomes directly editable in eclipse by simply selecting the php perspective (window > open perspective > php).
  • Or you import what you need into your default eclipse workspace. This way never worked for me. Maybe a real developer with some cvs experience can help you with that one.
  • I believe that you are trying to do both.

    I am not sure this will resolve your problem, though. Check to see if you are using an upacked jquery library. See dman's post above.

    I would love to get back to you on this but I am never going to find this thread again until the new drupal.org is launched. I can't find where to subscribe to these threads anywhere.

    Willem

    ...of je stopt de stekker erin.

    Newer versions of PDT

    Cyberwolf - September 28, 2009 - 07:42

    In newer versions of Eclipse / PHP Development Tools (PDT) the default text encoding setting is under Preferences > General > Workspaces.

    Settings in Zend Studio for Eclipse

    akaserer - October 17, 2009 - 10:36

    Line Indentiation in Zend Studio for Eclipse is found

    in Preferences:
    PHP -> Formater -> Edit: General settings:
    Tab policy: spaces
    Indetation size: 2

    not here:
    In the left-hand menu click on PHP -> Code Style ->
    Formatter: Set Tab policy: Spaces. Set Indentation size to 2.

    A new plug-in for Eclipse PDT / Zend Studio

    zvikico - October 27, 2009 - 07:40

    Introducing nWire for PHP: Real-time Code Analysis and Exploration Plugin for Eclipse

    I'd like to recommend a new tool which was recently released: nWire for PHP. It is a code exploration plugin for Eclipse PDT and Zend Studio 7. It enables code visualization, navigation and search. For large complex projects, like Drupal, this can be a big time saver. If you are doing custom Drupal development, you may find this a valuable addition to your arsenal.

    nWire for PHP was developed with support from the Zend Studio team. A fully functional 30-day free trial is available.

    Thanks,
    Zviki

     
     

    Drupal is a registered trademark of Dries Buytaert.