Eclipse tips/tricks/HOWTOs

$Id: eclipse.txt 1886 2008-08-11 17:10:03Z mjs $

HOWTO: Install

  1. To get the PDT package, download an "all-in-one" package from Zend. (More info.)

  2. Install Mylyn via "Search for new features to install". Mylyn remote site update URL; it should look something like:

    http://download.eclipse.org/tools/mylyn/update/e3.3

    (Be sure to install the Trac connector.)

  3. Install Subclipse (source).

    Note that you probably don't want to install anything from the "Integrations" node--these need dependencies you probably don't have.

    Note: if an eclipse update complains about a org.eclipse.datatools.doc.user dependency failing, try installing DTP first via the "Search for new features to install" option. (more info)

HOWTO: Enable emacs keybindings

Go to Window | Preferences | Workbench | Keys, and set Active Configuration to "Emacs". Note that the "Content Assist" facility is remapped from Control-space to Alt-/.

This gets you everything except Ctrl-W; to get Ctrl-W working as well:

Open eclipse/plugins/org.eclipse.ui_2.1.0/plugin.xml, and search for command="org.eclipse.ui.edit.text.showRulerContextMenu". You'll eventually find the ctrl-w binding; change it to something different such as ctrl-!. (more info)

HOWTO: Import a project from subversion into eclipse

i.e. you want both the "PDT" nature and the subversion nature, and you haven't checked out a working copy yet. (If you do have a working copy, see below.)

Do the subversion checkout first; as you're finishing with the wizard it will ask you how you want the project checked out--choose "Check out as a project configured using the New Project Wizard". Choose "PHP Project" at this point.

HOWTO: Import an existing eclipse project into eclipse

i.e. a directory with .project file; perhaps a project that's been "deleted" from Eclipse, but not from disk.

Use File | Import... | Existing Projects into Workspace, then choose the parent directory of the project you want to import as the root directory. Select the big "Projects" window, and Eclipse will scan the root directory for projects to import. (Note that it may take a long time to scan the directory.)

HOWTO: Import a directory into eclipse

i.e. a directory without .project file.

Use the File | New PHP Project, and use a project name that expands to a directory that already exists. Eclipse will detect that there's already stuff in that directory, and (if it's a working copy) subclipse will also (eventually) add its annotations. (If the annotation aren't being added, click around the project tree a bit and wait a few minutes.)

FAQ: Why are my ant builds failing?

(org.apache.catalina.ant.DeployTask cannot be found)

This may be operating under a slightly different classpath than eclipse. For example, junit stuff may work correctly under eclipse, but since junit.jar isn't in the default build path of ant, ant might not be able to build.

What you might have problems with:

junit:

c:/Program Files/eclipse/plugins/org.junit_3.8.1/junit.jar

tomcat/catalina:

c:/server/tomcat-5.0.28/server/lib/catalina-ant.jar

(Add them using Window | Preferences | Ant | Runtime.)

HOWTO: Get Tomcat to automatically reload classes

Add the following fragment to conf/server.xml, just below <Host name="localhost"...> (more info):

<DefaultContext reloadable="true">
  <Loader checkInterval="1"/>
</DefaultContext>

This should be the only change to Tomcat's configuration that you need to make--everything else should be configured by the web.xml/build.xml/build.properties in your application's directory.

TIP: ant buildfiles complain about catalina tasks being missing

Window | Preferences | Ant | Global Entries | Add External Jar

Add catalina-ant.jar from $CATALINA_HOME/server/lib. (Not the ant JARs in $CATALINA_HOME/common/lib!)

HOWTO: Associate a file extension with a particular content type

(If it's opening in the wrong editor, say.)

Use: General | Editors | File Associations.

You'd think it would be possible to map an extension to a particular view/syntax highlight using this, but it seems that at least in some circumstances, you also have to say that a particular "Content Type" can be mapped to a particular file extension.

e.g. Setting the default editor of *.html to "PHP Editor", but this doesn't do anything--this will only work once you also set the "File associations" of the "PHP Content Type" to *.html.

If you're trying to change the association of a "locked" extension, see below.

HOWTO: Comment region

Ctrl-/

HOWTO: View keybindings

Ctrl-Shift-L

HOWTO: Install the Xdebug debugger

See php.txt.

FAQ: Why does Xdebug launch Notepad?

(Incorrect Xdebug launch url.)

If, when launching Xdebug, notepad launches and then complains about a "file" with a name like:

C:\Documents and Settings\Michael Stillwell\http://ski.ms/simpletest/reservation.html?XDEBUG_SESSION_START=ECLIPSE_DBGP&KEY=119143983189813

not being able to be found, try switching Eclipse's default web from the internal browser to Firefox. (You may be able to switch it back again afterwards.)

FAQ: Project not recognised as having subversion

(i.e. if the subversion labels/badges and menu items aren't available.)

I don't know how to fix this (other than checking out the project again). In Eclipse terminology; the fix involves adding the subversion "nature". (This problem seems to happen less frequently these days.)

HOWTO: Revert update manager to asking for a download source

(i.e. if you let it automatically choose the download location, and now it's trying to pull updates from Bulgaria.)

You may be able to use the "Automatically select mirrors" checkbox on the "Help | Software Updates | Find and install... | Next" page.

HOWTO: Release "locked" content types

The locking is done via a the plugin.xml files are scattered through the plugins directories and plugins/*.jar (zip) files. To removed a "locked" file association, you need to find a chunk of XML that looks something like:

<content-type id="javaClass" name="%javaClassName" 
    priority="high"             
    file-extensions="class">
    <describer
        class="org.eclipse.core.runtime.content.BinarySignatureDescriber">
        <parameter name="signature" value="CA, FE, BA, BE"/>
    </describer>
</content-type>

and remove it or comment it out. Then, go into the configuration directory and delete everything except the config.ini file. (Might be possible to delete less, but I haven't figured out exactly what it's necessary to delete.)

Some guy's shell script to help find the right plugin.xml

FAQ: How can I reformat comments?

???

(The "format" command (Shift-Apple-L) reformats source code, but doesn't touch comments...)

FAQ: How can I eliminate the "The file has changed on the filesystem. Do you want to load the changes?" warning?

???

FAQ: Where's the Preferences menu item gone?

If you're using Zend Studio for Eclipse, for some reason the "Preferences ..." menu doesn't appear immediately after startup--you have to wait for a few minutes until it appears (!). (It appears at the same time as the subversion "nature" becomes available.)

ERROR: "resource is out of sync with the file system"

You can fix this for a single file by selecting "Refresh" from the file's context menu. To automatically refresh (I don't know why it doesn't do this automatically, like everything else...) enable "Refresh automatically" from the General | Workspace preferences.