Java Tutorial - Java Script : Installing Jetty

Java Tutorial - Java Script :

Installing Jetty


In order to install Jetty you will first need to download the files for your system. The files can be accessed from http://jetty.mortbay.org. If you are using Windows, Jetty is available as a .zip archive file. It is also available as a gzip-compressed .tar archive file for Linux systems. Other than the compression mechanism, these files are the same. You will also need to have previously installed and tested the Java Developers Kit (JDK). We suggest using JDK 1.4 or later. For Windows, use your favorite unzipping tool to unzip the package, preserving the subdirectory names. We suggest that Jetty be placed in a subdirectory named jetty below the root directory of a drive. On Linux, Jetty can be unpacked using the command: tar zxvf Jetty-2.4.2.tgz This will decompress and de-archive the file in one step. We suggest that this be done either in a directory named jetty below your home directory
(for personal use) or in /usr/local/jetty. Once Jetty has been unpacked, it can be started on any platform by using the command: java -jar start.jar from the jetty subdirectory. The file start.jar should be in this directory. The default configuration for Jetty listens on port 8080. The installation can be tested on the server by entering the following
URL into a browser running on the same machine: http://localhost:8080 If Jetty is running, you should see the screen similar to the one shown in Figure 5.3.

 You should also test to make sure that JavaServer Pages are working. To do this, enter the following URL or follow the Demo link on the left of the startup page and then follow the JSP link. http://localhost:8080/jetty/demoJSP.html This provides a short list of JSP examples that are installed into jetty. We suggest that you try the snoop example and make sure it works. Snoop returns information about the HTTP request that invoked the page. If you want to change the port that Jetty uses, edit the file jetty.xml, which can be found in the jetty/etc directory. This is important if you want to test another servlet container that may also use port 8080 (like Tomcat for example). We normally change Jetty to use port 8186. Just search on the string 8080 and replace it with the new port number. You should also add a line to the file jetty/etc/demoRealms.properties in order to add yourself as an administrator. The following line appended to demoRealms adds a user named super with a password of boss and both administrator roles recognized by Jetty. admin:adminpasswd,server-administrator,content-administrator After this is done and the container is restarted, you will be able to use Jetty’s simple administration screen shown in Figure 5.4. Jetty’s administration utility allows the administrator to stop and stops almost any activity within the server. This feature allows us to stop an individual application, update it in place on the server, and then restart it without affecting the rest of the applications running on the server. The administration page can also be used to shut down the server. Deploying a new Web application on Jetty requires additions to Jetty’s configuration files. The configuration files can be found in the /etc directory in the Jetty installation directory. For example, adding the following lines to the “add contexts” section of the file demo.xml will install the Web application myapps located in the /webapps/myapps directory below JETTY_HOME.
<Call name=”addWebApplication”>
<Arg>/myapps/*</Arg>
<Arg>
<SystemProperty name=”jetty.home” default=”.”/>
/webapps/myapp
</Arg>
</Call>
Although this may seem complicated at first, the configuration language is
well documented and easy to learn.