Want to show your appreciation?
Please a cup of tea.

Friday, January 20, 2012

Jetty and Eclipse

Introduction

This page helps to setup Jetty as your local development server. I covers installation, configuration and manage the Jetty within Eclipse IDE.

Installation

Download the Jetty core component binary from the Jetty downloads page. Select the version that is required by your project. You can install multiple version of Jetty as long as you don’t run them on same port at the same time. Here are the direct links to recent Jetty versions:

Download the .zip (or .tar.gz preferable for Linux and OSX) file and decompress it. It will be extracted into a directory called jetty-distribution-VERSION. Put this directory into a convenient location. This location will be referred as either JETTY_HOME or as $(jetty.home) on Jetty Wiki.

Jetty Eclipse Plugin

Plugin Installation

Please refer to the Web Tools Platform section of Install Eclipse and Commonly Used Plugin page and make sure "WST Server Adapters" is installed.

Add Jetty Server

Follow the instructions below to add your Jetty server to Eclipse so you can manage the server and deploy web application within Eclipse IDE.

  1. Open “Servers” window.

    Show View For detailed instructions on how to show feature window, please refer to Access Feature Window section of Install Eclipse and Commonly Used Plugin.

  2. Right click on the blank area of “Servers” window and select “New->Server” context menu.
    jetty-new-server
  3. Type “jetty” as the filter text. Select the “Jetty v#.# Server” where #.# should be the same version of Jetty server or one version lower if a match doesn’t exist. Then click “Next >” to continue.
    jetty-server-type
  4. Enter the home where the specific version of Jetty is installed, then click on “Finish”. You should see the newly added entry in the “Servers” window.
    jetty-server-dir

Deploy Web Application to Jetty Server

  1. Open “Servers” window.

    Show View For detailed instructions on how to show feature window, please refer to Access Feature Window section of Install Eclipse and Commonly Used Plugin.

  2. Right click on the server to where the application will be deployed, then select “Add and Remove…” context menu item.
    jetty-add-remove-menu
  3. Change the application(s) to deploy to the server using Add/remove buttons. Click on “Finish” button when you are done.
    jetty-add-webapp
  4. You should see the applications deployed are listed beneath the server. And you can start/stop/debug/profile the server using the toolbar buttons.
    jetty-add-webapp
  5. From the console, you can see the application is deployed and Jetty started successfully.
    jetty-console

Change Settings

Instructions below shows you how to adds environment variables and change module path. By going through those step, you can also get a general sense of how to change the settings of Jetty server in Eclipse.

  1. Open “Servers” window

    Show View
    For detailed instructions on how to show feature window, please refer to Access Feature Window section of Install Eclipse and Commonly Used Plugin.

  2. Double click on the server to open the server settings window.
    jetty-open-server
  3. You can use this window to change listening port and other properties. Then click on “Open launch configuration” link.
    jetty-settings
  4. In the “Edit launch configuration properties” dialog, make necessary changes to parameters start Jetty included environment variables. Then click “OK”.

    jetty-launch-env

  5. When you are back to the server window, click on the "Modules" at the bottom, select the application module you want to edit and change the Path value according to your project documentation.
    jetty-edit-module
  6. Save your changes by using Eclipse menu item "File->Save".

Troubleshooting

Q: No permission to /var/log/jetty
A: This happens to OSX and Linux users. The fix is to create the log directory and give proper permission.

sudo mkdir -p /var/log/jetty/applogs
sudo mkdir -p /var/log/jetty/weblogs
sudo chmod -R a+w /var/log/jetty/*

Q: Address already in use
A: When you encounter below error when start Jetty:

WARN::FAILED SelectChannelConnector@0.0.0.0:80: java.net.BindException: Address already in use

There are two possible causes:

  1. The previous run instance wasn’t fully shutdown before the Jetty was restarted. This can be resolve by retrying again.
  2. Another application is using the same port. You must stop that conflicting application or have that application use a different port. To find out which application is using the port,
    • On Windows, TCPView is a great GUI tool for this purpose. You can also quickly find out using command line utility.
      To find out process ID (a short list):
      netstat -aonp TCP | find -i "listening"

      To find out process name (a long list):

      netstat -abnp TCP
    • On OSX and Linux, use below command.
      lsof -i

1 comment:

Avijit said...

You have composed an exceptionally educational article with incredible quality substance and all around spread out focuses. I concur with you on a large number of your perspectives and you have me thinking.


SEO services in kolkata
Best SEO services in kolkata
SEO company in kolkata
Best SEO company in kolkata
Top SEO company in kolkata
Top SEO services in kolkata
SEO services in India
SEO copmany in India

Post a Comment