In Eclipse, you can build, run, and debug your web applications using Lift’s Maven archetypes. The following steps were tested on Eclipse Galileo.
You’ll need to download and install Eclipse for Java or Java EE. Then install the M2Eclipse, Scala IDE, and M2Eclipse-Scala plugins. M2Eclipse explains how to install using Eclipse update sites, and you can do the same for Scala IDE using its update site.
Create a Lift project
The following steps create a Lift application from an archetype, as explained in Exploring Lift, but using Eclipse instead of on the command line.
- In the Eclipse workbench, start a new project by selecting File → New → Project from the menu bar at the top.
- In the New Project dialog, select Maven → Maven Project and click Next.
- In the next dialog, make sure that Create a simple project is unchecked, and click Next.
- If this is your first time doing this, you’ll need to add the Scala repository to list of artifacts. Click Configure in the next dialog, then click Add Remote Catalog, paste http://scala-tools.org/repo-releases/ into the Catalog File field, then click OK and OK again (the M2Eclipse-scala plugin makes this step unnecessary).
- Once the catalog downloads, you should see many net.liftweb entries in the list of artifacts. Select the Lift artifact that you want to base your project on. Make sure the version suffix matches the Scala IDE version. The Scala IDE page indicates the Scala version used by the plugin. For example, you can select lift-archetype-blank_2.8.1 if you want a blank application and your Scala IDE is master-2.8.1.final. Once you’ve selected an archetype, click Next.
- In the next dialog, specify any value you want in the Group Id and Artifact Id fields, then click Finish.
- If this is your first time, it will take a while to download all of the required dependencies. You can watch the progress in the Console pane that is usually at the bottom of the workbench.
- Once Maven is done, you should see your new project in the Project Explorer, but it probably will not build correctly. Right click on the project name in the Project Explorer and select Configure → Add Scala Nature. This will configure it as a Scala project. The project should then rebuild without errors (the M2Eclipse-scala plugin also makes this step unnecessary).
Build, run, and debug
Standard Maven operations are available in the Run As menu. For example, to create a .war file:
- Select Run → Run As → Maven package from the menu bar at the top.
- You can watch the progress in the Console. Once it completes, expand the directory named target under your project in the Project Explorer , and you should see a .war file with your web application.
You can run and debug your program by configuring Maven launches in the Run Configurations and Debug Configurations dialogs. For example, to debug your web application:
- Select Run → Debug Configurations from the menu bar at the top.
- Double-click on Maven Build to create a new Maven run configuration.
- To fill in the Base directory field, click Browse Workspace, select your project name in the dialog, and click OK.
- In the Name field at the top of the dialog, give the configuration any name you want, then in the Goals field, type jetty:run and click Debug. This will create the configuration and start your web application.
- To see that you can debug your application, open up some file that you know will be called when you request a page, double-click on the left edge of the editor pane on the line where you want to break, then open that page in your web browser. For example, in an application named demo.helloworld created from the blank archetype, set a break-point in demo.helloworld.snippet.HelloWorld.howdy(), then open http://localhost:8080/ in your web browser.
- Once the request is processed, Eclipse should open the debug view and show the application stopped at the break-point. You can step, resume, stop, and use all of the standard Eclipse debugging features.
- To get back to the Java perspective when you’re done, click Java near the upper right hand corner of the workbench.
- To run or debug again later, you can go use the Run Configurations and Debug Configurations dialogs, or you can click the small down arrow beside the bug or play icons underneath the menu bar, and select the name that you specified when you created the run configuration.