Developer How-To Use Eclipse Guide


Contents

How to incorporate Subversion within Eclipse

There is an Eclipse plugin for subversion called subclipse.

From the Eclipse menu, select Help → Software Updates → Find and Install...
Enlarge
From the Eclipse menu, select Help → Software Updates → Find and Install...


Select Search for new features to install from the Install/Update dialog.
Enlarge
Select Search for new features to install from the Install/Update dialog.


 Then put in the Eclipse update site for subclipse in as a New Remote Site....
Enlarge
Then put in the Eclipse update site for subclipse in as a New Remote Site....


Enlarge


For Eclipse 3.2 and 3.3, the URL with subversion 1.2.x, the URL is http://subclipse.tigris.org/update_1.2.x
Enlarge
For Eclipse 3.2 and 3.3, the URL with subversion 1.2.x, the URL is http://subclipse.tigris.org/update_1.2.x


Select the Subclipse feature to be installed
Enlarge
Select the Subclipse feature to be installed


Agree to the license
Enlarge
Agree to the license


Click the Finish button and the Eclipse subclipse plugin will be installed.
Enlarge
Click the Finish button and the Eclipse subclipse plugin will be installed.

How to Debug a Web Application with Eclipse

Add the following to the java command used to launch Tomcat (e.g., in the service settings if running as a Windows service):

-Xdebug
-Xnoagent
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5000


Within Eclipse, Click on the debug button (or Run → Debug... or Run → Open Debug Dialog... through the menu) to open the debug window.
Enlarge
Within Eclipse, Click on the debug button (or Run → Debug... or Run → Open Debug Dialog... through the menu) to open the debug window.


Under configurations you’ll find an entry "Remote Java Application."  Create a new Remote Java Application, choose a project, leave the connection type to "standard (socket attach)," and for connection properties choose "localhost" and "5000" (change these if you’re using a different port or a different machine to run tomcat).
Enlarge
Under configurations you’ll find an entry "Remote Java Application." Create a new Remote Java Application, choose a project, leave the connection type to "standard (socket attach)," and for connection properties choose "localhost" and "5000" (change these if you’re using a different port or a different machine to run tomcat).

Start up tomcat and then debug with this new Remote Java Application and breakpoints within the code will open within Eclipse.

  • Notes:
    • Tomcat 6 users start debugging by running catalina.sh jpda start to debug on port 8000

How to 'Watch' Variables (while debugging)

While debugging a program, select (highlight) a variable or expression and then select Watch from the Run menu or context menu.

Toggling breakpoints in your code

Use the Window → Show View → Other... menu item to open a dialog of possible views. Find Debug → Breakpoints and select it. The breakpoints view will list all defined breakpoints and let you optionally enable/disable/remove them.

Tune the MyEclipse environment (commercial, optional)

  • Speed up JSP files by turning off validation and changing the default editor
    • Under Window -> Preferences, make the following changes:
      • Make the 'Classic' JSP editor the default — Go to General -> Editors -> File Assocations -> .jsp and set MyEclipse 'Classic' JSP Editor as default
      • Turn off JSP validation — Go to MyEclipse -> Validation and uncheck JSP Validator

How to Create a Project with Existing Source

Use Case

  1. You have an existing Eclipse workspace folder.
  2. You no longer have projects in Eclipse for the source code in the workspace folder.

Solution

Open the Eclipse Wizard and 'Create a Java project.'
Enlarge
Open the Eclipse Wizard and 'Create a Java project.'


Click 'Create project from existing source.'  Browse the source folder in the workspace.  For the Project name, type in the name of the source folder.  Then Finish.
Enlarge
Click 'Create project from existing source.' Browse the source folder in the workspace. For the Project name, type in the name of the source folder. Then Finish.

How to Install OpenMRS Code Style

  • We use the automatic formatting feature of Eclipse to generate consistently formatted code
    • Simply use control-shift-f to format a file
    • OpenMRS formatting file for Eclipse: OpenMRSFormatter.xml
      • Install at Window -> Preferences -> Java -> Code Style -> Formatter
    • OpenMRS code template file for Eclipse: OpenMRSCodeTemplate.xml
      • Install at Window -> Preferences -> Java -> Code Style -> Code Templates
  • Use control-shift-o for finding/formatting/organizing imports - Very useful!