AddThis

Friday, August 26, 2011

Setting up Jetty to run inside of Eclipse

Jetty is a great lightweight server that I'm using to do both my frontend and backend development.  For the focus of this tutorial, we will have a frontend slant.  This tutorial in particular will cover how to setup Eclipse (Helios) to deploy my webapp to Jetty so that I can quickly see my UI tweaks and changes.

Install Jetty
  1. Help -> Install New Software
  2. Work with: http://download.eclipse.org/jetty/updates/jetty-wtp
  3. Click Add
  4. Install Jetty and restart Eclipse

Prepare Your Web Project
  1. cd ${YOUR_WEB_PROJECT}
  2. mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true
  3. Import your project into eclipse as an existing project
  4. Right click your web project and go to Project Facets
  5. Click Dynamic Web Module
  6. Select Deployment Assembly
  7. Make sure your Deploy Path: / is the directory one above where WEB-INF lives.
    1. If not, go to Add... -> Folder and select WEB-INF's parent folder (It'll be something like webapp, or WebContent).
  8. Now click Add.. -> Java Build Path Entries
  9. Select them all using shift for multiselect and click ok


Prepare Jetty and Eclipse
  1. Click Window -> Show view -> Servers
  2. Right click the servers view -> New -> Server
  3. Select Jetty 8 or whatever you fancy
    1. Server's host name: localhost
    2. Server's name: Whatever you want
    3. Server runtime environment: click the add button on the right
      1. Name: Whatever
      2. Jetty installation directory: click the Download and Install button to the right -> Accept agreement -> select a location to download
      3. This is important....Wait a bit for the download to complete (look at the eclipse progress in the lower right and wait for it to complete.  
      4. When done, set the Jetty installation directory to the directory you just downloaded and installed jetty to
    4. JRE: Don't let this fool you, configure it to point to a jdk, not a jre.  
      1. If you don't have one, dl it and configure it using the Installed JREs... button
  4. Click Next
  5. Select your ${YOUR_WEB_PROJECT} to add as a deployment
  6. Click Finish


Setup Realms for Login
  1. Open up etc/realm.properties and add in your favorite user and passwords (USER1: password,role1,role2)
  2. Save and close
    1. If you edit this file later to add more users, remember to clean and publish for the changes to be picked up.  You do this by right clicking the server in the servers view and selecting clean.  After its finished, right click it again and select republish/publish.


Setup Ports
  1. Double click the server you just created to open up its configuration
  2. Select the Overview tab
  3. Look for the Ports section
  4. Click HTTP and change to whatever port you want


Usage
Right Click the server in the Servers view to manage the server.  You'll be able to start, stop, restart, and debug from here.


And thats's pretty much it.  Super easy and straightforward.
Post a Comment