Enterprise Java for Linux HOWTO <author>Greg Wilkins <tt>gregw@mortbay.org<label id="sec: author"></tt> original by Gary Meyer <tt>gary@meyer.net</tt> <date>v0.2, 2001-11-07 <abstract>How to set up an Enterprise Java environment on Linux including a Java Development Kit, a Web server, supporting Java servlets, accessing a database via JDBC, and supporting Enterprise Java Beans (EJBs). <toc> <sect>Introduction<label id="sec: intro"> <p> <sect1>Background <p> This document was started January, 1999 by Gary Meyer ( <htmlurl url="mailto:gary@meyer.net" name="gary@meyer.net">) after several weeks of installing various open source and proprietary Enterprise Java products for Linux. "Enterprise Java" is defined as using the Java Enterprise APIs. <p> Some updates were added by Greg Wilkins (<htmlurl url="mailto:gregw@mortbay.org" name="gregw@mortbay.org">) in November 2001 however parts of the document are still out of date. <sect1>Audience <p> This HOWTO is intended to benefit software professionals who are interested in evaluating, developing, or deploying Enterprise Java on Linux. Limited knowledge or experience in either Linux or Java is assumed. <sect1>New Versions <p> The newest version of this document can be found at the Linux Documentation Project website at: <htmlurl url="http://linuxdoc.org/HOWTO/Enterprise-Java-for-Linux-HOWTO.html" name="http://linuxdoc.org/HOWTO/Enterprise-Java-for-Linux-HOWTO.html"> <sect1>Copyright and License <p> This document is Copyright (c) 1999-2001 by Gary Meyer and Greg Wilkins. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is available at <htmlurl url="http://www.gnu.org/copyleft/fdl.html" name="http://www.gnu.org/copyleft/fdl.html"> <sect1>Disclaimers <p> The suggestions in this document are provided to help you get a Enterprise Java environment on Linux up and running as quickly as possible. The suggestions are not product recommendations or endorsements. As you become familiar with the options available, you can do you own product evaluations and determine what options are best for your particular purpose. For the purpose of this HOWTO, "Enterprise Java" is defined as using the Java Enterprise APIs. This HOWTO does not address scalability, availability, manageability, and other such aspects of software that are often associated with the word "enterprise." <sect1>Potential Future Sections <p> This HOW has focused on the most popular aspects of Enterprise Java. The following sections may be added to this HOWTO. <itemize> <item>Integrated Development Environments (IDEs) that Support Enterprise Java for Linux <item>Java Naming and Directory Interface (JNDI) Support <item>Java Mail API (JMAPI) Support <item>Java Transaction Service (JTS) Support <item>Java Interface Definition Language (JIDL) Support <item>Java Messaging Service (JMS) Support <item>Common Object Request Broker Architecture (CORBA) Support </itemize> Interested in authoring a section? Please contact the author, Gary Meyer, at ( <htmlurl url="mailto:gary@meyer.net" name="gary@meyer.net">). <sect1>Other Resources <p> The App-Serv Center website at <htmlurl url="http://www.app-serv.com/" name="http://www.app-serv.com/">. Java Enterprise in a Nutshell by David Flanagan et al at <htmlurl url="http://www.oreilly.com/catalog/jentnut/" name="http://www.oreilly.com/catalog/jentnut/">. <sect1>Feedback <p> Please submit all additions and corrections to the author, Gary Meyer, at (<htmlurl url="mailto:gary@meyer.net" name="gary@meyer.net">). <sect>How to Setup the Java Development Kit <label id="sec: jdk"> <p> There are several Java Development Kits available for Linux. These include: <itemize> <item><ref id="sec: blackdown" name="Blackdown JDK"> <item><ref id="sec: ibmjdk" name="IBM Java Developer Kit "> <item><ref id="sec: j2se" name="Sun J2SE "> <item><ref id="sec: kaffe" name="Kaffe "> </itemize> If you are going to try just one JDK, I suggest you initially try the Sun J2SE, unless you are recommended otherwise by specific software you are using or want to use. Additionally, if you are interested in an open source implementation, you will need to use Kaffe. <sect1>Blackdown JDK <label id="sec: blackdown"> <p> <sect2>Background <p> The Blackdown JDK is a port of Sun JDK to Linux. As of the time of this writing, the Blackdown JDK is current with JDK 1.2.2 on the Intel architecture and 1.1.8 on the PowerPC. In December 1999, Sun announced availability of the Java 2 Platform, Standard Endition (J2SE) on Linux. This Sun release has significant impact on Blackdown because Blackdown is a port. In a press release, Sun states, &dquot;This week's announcement would not have been possible without the collaboration of Blackdown, a group of developers and enthusiasts around the globe. Since its inception, Blackdown has been a provider of Java technology for the Linux platform. Their dedicated effort over a number of years has laid the foundation for this release of the Java 2 platform port to Linux; in particular their effort was critical to the success of this release.&dquot; Additionally, the Sun press release continues, &dquot;Blackdown.org continues to be a valuable source for Java technology for Linux, including JDK 1.1.x releases.&dquot; <sect2>Download <p> The Blackdown JDK can be obtained from <htmlurl url="http://www.blackdown.org" name="http://www.blackdown.org">. >From the Blackdown home page, select download and a mirror site. Select the version of the JDK you want. If other software that you are wanting to use does not recommend a specific version, I suggest the most current, which is at the time of this writing, JDK 1.2.2. Select the machine architecture you are installing on. For Intel architecture, select i386. Select the release candidate you want. If other software that you are wanting to use does not recommend a specific release candidate, I suggest the most recent or final version if available. For the Blackdown JDK, there are possibly a number of different files available in different packaging formats. Additionally you have to be sure you get support for the right libc for your Linux distribution. The files available include: <itemize> <item><em>jdk</em> - The Java Development Kit contains everything you need to compile, run, and debug Java. It does not contain international character converters. <item><em>jre</em> - The Java Runtime Environment, including international character converters. <item><em>rt</em> - A minimal Java Runtime Environment that does not include international character converters. <item><em>i18n</em> - The internationalization font mappings and a JAR containing the international character converters. <item><em>native</em> - Additional binaries providing native thread support. </itemize> I suggest downloading only the jdk for Java development in English. When downloading the Blackdown files, you may need to select between libc5 and glibc as well as potentially a specific version of glibc. The libc options include: <itemize> <item>libc5 - The older, and still most common, Linux libc is libc5. <item>glibc - The new Linux libc. </itemize> If you are using a newer distribution of Linux, you will most likely have glibc. I suggest initially trying glibc. <sect2>Installation <p> I suggest installing files in the /usr/local directory. After downloading the files, run: <verb>mkdir /usr/local/blackdown mv jdk* /usr/local/blackdown </verb> If you downloaded the tarball format, run: <verb>tar zxvf [filename].tar.gz </verb> Where [filename] is the name of the file. Under the /usr/local/blackdown directory, you now should see a directory such as jdk1.2.2. The above example shows JDK 1.2.2 release candidate 3 for the Intel architecture. Substitute the file name, version number, release candidate number, and architecture as appropriate. You will need to open each distribution package file in the above manner. <sect2>Setting up Your Environment <p> The environment variables to set up are: <itemize> <item>JAVA_HOME <item>PATH <item>CLASSPATH </itemize> The JAVA_HOME environment variable references the home directory of your JDK installation. Set your JAVA_HOME environment variable to the directory into which you just installed a version of the Blackdown JDK. <verb>export JAVA_HOME=/usr/local/blackdown/jdk1.2.2 </verb> The $JAVA_HOME/bin directory has the Java compiler (javac) and the Java Virtual Machine (java) as well as other necessary programs for development. Add $JAVA_HOME/bin to your PATH. <verb>export PATH=$JAVA_HOME/bin:$PATH </verb> Note that $JAVA_HOME/bin was added to the front of the PATH so that the installed JDK will be used rather than any JDK that might have come with your Linux distribution. To confirm that your PATH is correctly set up, check which Java compiler and JVM will be used. <verb>which javac which java </verb> The output should reference javac and java in your $JAVA_HOME/bin directory. The CLASSPATH environment variable references all JARs and directories that you will need to compile and run Java programs. For JDK 1.2.2, you don't need to initially add any JARs to your CLASSPATH. JARs can be packaged in either .jar or .zip files. <verb>export CLASSPATH=$CLASSPATH:. </verb> <sect2>Confirming Your Installation <p> You are now ready to compile and run a simple application. Create the following program. <verb>class HelloWorld { public static void main (String[] args) { System.out.println(&dquot;Hello, World!&dquot;); } } </verb> Compile the program with the Java compiler. <verb>javac HelloWorld.java </verb> If the compiler produces errors, double check the syntax and confirm your PATH and CLASSPATH. Run the program with the JVM. <verb>java HelloWorld </verb> If the JVM produces errors, confirm your PATH and CLASSPATH. You should see the following output: <verb>Hello, World! </verb> Congratulations, you have installed, set up an environment for, and tested the Blackdown JDK on Linux. <sect2>More Information <p> For more information on the Blackdown JDK, see the Blackdown website at <htmlurl url="http://www.blackdown.org" name="http://www.blackdown.org">. There is an excellent FAQ available. <sect1>IBM Java Developer Kit <label id="sec: ibmjdk"> <p> <sect2>Background <p> The IBM Java Developer Kit and Runtime Environment pass Sun's Java compatibility test and include the latest maintenance. (From the IBM website.) As of the time of this writing, the IBM Java Developer Kit is current with JDK 1.1.8 and is available only on the Intel architecture. <sect2>Download <p> The IBM Java Developer Kit can be obtained from <htmlurl url="http://www.ibm.com/java/jdk/118/linux" name="http://www.ibm.com/java/jdk/118/linux">. In order to download, you will have to register with the IBM website and agree to the license online. The files available include: <itemize> <item><em>ibm-jdk-l118-linux-x86.tgz</em> - The Java Development Kit contains everything you need to compile, run, and debug Java. <item><em>ibm-jre-l118-linux-x86.tgz</em> - The Java Runtime Environment contains everything you need to run Java. </itemize> Since you will be doing Java development, I suggest downloading the ibm-jdk tarball file. <sect2>Installation <p> I suggest installing files in the /usr/local directory. After downloading the files, run: <verb>mkdir /usr/local/ibm mv ibm-jdk-l118-linux-x86.tgz /usr/local/ibm </verb> You can now open the distribution package. To do this, type: <verb>tar zxvf ibm-jdk-l118-linux-x86.tgz </verb> Under the /usr/local/ibm directory, you now should see the jdk118 directory. The above example shows JDK 1.1.8 for the Intel architecture. Substitute the filenames as appropriate. <sect2>Setting up Your Environment <p> The environment variables to set up are: <itemize> <item>JAVA_HOME <item>PATH <item>CLASSPATH </itemize> The JAVA_HOME environment variable references the home directory of your JDK installation. Set your JAVA_HOME environment variable to the directory into which you just installed a version of the IBM Java Developer Kit. <verb>export JAVA_HOME=/usr/local/ibm/jdk118 </verb> The $JAVA_HOME/bin directory has the Java compiler (javac) and the Java Virtual Machine (java) as well as other necessary programs for development. Add $JAVA_HOME/bin to your PATH. <verb>export PATH=$JAVA_HOME/bin:$PATH </verb> Note that $JAVA_HOME/bin was added to the front of the PATH so that the installed JDK will be used rather than any JDK that might have come with your Linux distribution. To confirm that your PATH is correctly set up, check which Java compiler and JVM will be used. <verb>which javac which java </verb> The output should reference javac and java in your $JAVA_HOME/bin directory. The CLASSPATH environment variable references all JARs and directories that you will need to compile and run Java programs. Initially I suggest adding the following JARs to your CLASSPATH. JARs can be packaged in either .jar or .zip files. For instance: <verb>export CLASSPATH=$JAVA_HOME/lib/classes.zip export CLASSPATH=$CLASSPATH:. </verb> <sect2>Confirming Your Installation <p> You are now ready to compile and run a simple application. Create the following program. <verb>class HelloWorld { public static void main (String[] args) { System.out.println(&dquot;Hello, World!&dquot;); } } </verb> Compile the program with the Java compiler. <verb>javac HelloWorld.java </verb> If the compiler produces errors, double check the syntax and confirm your PATH and CLASSPATH. Run the program with the JVM. <verb>java HelloWorld </verb> If the JVM produces errors, confirm your PATH and CLASSPATH. You should see the following output: <verb>Hello, World! </verb> Congratulations, you have installed, set up an environment for, and tested the IBM Java Developer Kit on Linux. <sect2>More Information <p> For more information on the IBM Java Developer Kit, see the IBM Java website at <htmlurl url="http://www.ibm.com/java" name="http://www.ibm.com/java">. <sect1>Kaffe<label id="sec: kaffe"> <p> <sect2>Background <p> Kaffe is a cleanroom, open source implmentation of a Java Virtual Machine and class libraries. As of the time of this writing, Kaffe &dquot;mostly complies with JDK 1.1, except for a few missing parts.&dquot; And &dquot;parts of it are already JDK 1.2 (Java 2) compatible.&dquot; (From the Kaffe website.) Kaffe may have already been shipped with your Linux distribution because of its open source license. <sect2>Download and Installation <p> Rather than downloading from Kaffe, I suggest you initially try the Kaffe that most likely came with your Linux distribution. Alternatively, Kaffe can be obtained from <htmlurl url="http://www.kaffe.org" name="http://www.kaffe.org">. >From the Kaffe home page, select the current release. At the time of this writing, the current release is 1.0.5. The Kaffe version number has no relationship to JDK specification version numbers. <sect2>Setting up Your Environment <p> The environment variables to set up are: <itemize> <item>PATH <item>CLASSPATH </itemize> To confirm that your PATH is correctly set up, check which Java compiler and JVM will be used. <verb>which javac which java </verb> The CLASSPATH environment variable references all JARs and directories that you will need to compile and run Java programs. Initially I suggest you add the following JARs to your CLASSPATH. JARs can be packaged in either .jar or .zip files. For instance: <verb>export CLASSPATH=/usr/local/share/kaffe/Klasses.zip export CLASSPATH=$CLASSPATH:. </verb> <sect2>Confirming Your Installation <p> You are now ready to compile and run a simple application. Create the following program. <verb>class HelloWorld { public static void main (String[] args) { System.out.println(&dquot;Hello, World!&dquot;); } } </verb> Compile the program with the Java compiler. <verb>javac HelloWorld.java </verb> If the compiler produces errors, double check the syntax and confirm your PATH and CLASSPATH. Run the program with the JVM. <verb>java HelloWorld </verb> If the JVM produces errors, confirm your PATH and CLASSPATH. You should see the following output: <verb>Hello, World! </verb> Congratulations, you have installed, set up an environment for, and tested Kaffe on Linux. <sect2>More Information <p> For more information on Kaffe, see the Kaffe website at <htmlurl url="http://www.kaffe.org" name="http://www.kaffe.org">. <sect1>Sun J2SE <label id="sec: j2se"> <p> <sect2>Background <p> The Sun Java 2, Standard Edition (J2SE) is Sun's production release of the Java 2 Platform for the Linux operating system. As of the time of this writing, J2SE is current with JDK 1.2.2 on the Intel architecture. <sect2>Download <p> J2SE can be obtained from <htmlurl url="http://developer.java.sun.com/developer/earlyAccess/j2sdk122" name="http://developer.java.sun.com/developer/earlyAccess/j2sdk122">. You will need to register with Sun and agree to the license online before downloading. <sect2>Installation <p> I suggest installing files in the /usr/local directory. After downloading the files, run: <verb>mkdir /usr/local/sun mv jdk1_2_2rc1-linux-i386.tar.gz /usr/local/sun </verb> You can now open the distribution package. To do this, type: <verb>tar zxvf jdk1_2_2rc1-linux-i386.tar.gz </verb> Under the /usr/local/sun directory, you now should see the jdk1.2.2 directory. The above example shows JDK 1.2.2 release candidate 1 for the Intel architecture. Substitute the filenames as appropriate. <sect2>Setting up Your Environment <p> The environment variables to set up are: <itemize> <item>JAVA_HOME <item>PATH <item>CLASSPATH </itemize> The JAVA_HOME environment variable references the home directory of your JDK installation. Set your JAVA_HOME environment variable to the directory into which you just installed a version of J2SE. <verb>export JAVA_HOME=/usr/local/sun/jdk1.2.2 </verb> The $JAVA_HOME/bin directory has the Java compiler (javac) and the Java Virtual Machine (java) as well as other necessary programs for development. Add $JAVA_HOME/bin to your PATH. <verb>export PATH=$JAVA_HOME/bin:$PATH </verb> Note that $JAVA_HOME/bin was added to the front of the PATH so that the installed JDK will be used rather than any JDK that might have come with your Linux distribution. To confirm that your PATH is correctly set up, check which Java compiler and JVM will be used. <verb>which javac which java </verb> The output should reference javac and java in your $JAVA_HOME/bin directory. The CLASSPATH environment variable references all JARs and directories that you will need to compile and run Java programs. For JDK 1.2.2, you don't need to initially add any JARs to your CLASSPATH. JARs can be packaged in either .jar or .zip files. <verb>export CLASSPATH=$CLASSPATH:. </verb> <sect2>Confirming Your Installation <p> You are now ready to compile and run a simple application. Create the following program. <verb>class HelloWorld { public static void main (String[] args) { System.out.println(&dquot;Hello, World!&dquot;); } } </verb> Compile the program with the Java compiler. <verb>javac HelloWorld.java </verb> If the compiler produces errors, double check the syntax and confirm your PATH and CLASSPATH. Run the program with the JVM. <verb>java HelloWorld </verb> If the JVM produces errors, confirm your PATH and CLASSPATH. You should see the following output: <verb>Hello, World! </verb> Congratulations, you have installed, set up an environment for, and tested the Sun J2SE for Linux. <sect2>More Information <p> For more information on Sun J2SE, see the Sun Java website at <htmlurl url="http://java.sun.com" name="http://java.sun.com">. There are excellent discussion forums available where you might be able to find answers to various questions. <sect>How to Setup the Web Server <label id="sec: web"> <p> There are several Web Servers available for Linux. These include: <itemize> <item><ref id="sec: apache" name="Apache "> <item><ref id="sec: domino" name="IBM Domino "> <item><ref id="sec: ibmhttp" name="IBM HTTP Server "> <item><ref id="sec: jetty" name="Jetty HTTP Server"> </itemize> If you are going to try just one Web Server, I suggest you initially try Apache, principally because it comes with most major Linux distributions and may already be installed, and perhaps running, on your system. <sect1>Apache <label id="sec: apache"> <p> <sect2>Background <p> Apache is the most popular HTTP server on the Internet. It was originally based upon the NCSA httpd and has since been completely rewritten. It is Open Source licensed. (From the Apache website.) <sect2>Download, Installation, and Setting up Your Environment <p> Rather than downloading from Apache, I suggest you initially try the Apache that most likely came with your Linux distribution. Alternatively, Apache can be obtained from <htmlurl url="http://www.apache.org" name="http://www.apache.org">. <sect2>Confirming Your Installation <p> To confirm that Apache is installed and running on your computer, open your web browser, and enter the URL: &dquot;http://127.0.0.1&dquot;. (127.0.0.1 is the IP address for the localhost.) You should see a web page to the effect of &dquot;It Worked!&dquot; If it did not work, you can confirm that Apache is installed by typing the following on a RedHat Package Manager (RPM)-based Linux distribution. <verb>rpm -q | grep apache </verb> To start Apache, type: <verb>cd /etc/rc.d/init.d ./httpd start </verb> Note: The httpd script used at boot time may be in a different location on other Linux distributions. For more assistance, I suggest you look into the Apache FAQ at <htmlurl url="http://www.apache.org/docs/misc/FAQ.html" name="http://www.apache.org/docs/misc/FAQ.html">. <sect1>IBM Domino <label id="sec: domino"> <p> To be written. See <htmlurl url="http://www.lotus.com/dominolinux" name="http://www.lotus.com/dominolinux">for more information. <sect1>IBM HTTP Server <label id="sec: ibmhttp"> <p> <sect2>Background <p> The IBM HTTP Server is an IBM repackaging of Apache. You might consider using the IBM HTTP Server if you plan on working with IBM WebSphere. At the time of this writing, the most recent version is 1.3.6.1. <sect2>Download <p> The IBM HTTP Server can be obtained from <htmlurl url="http://www-4.ibm.com/software/webservers/httpservers/download.html" name="http://www-4.ibm.com/software/webservers/httpservers/download.html">. Click on the download link and select 56-bit or 128-bit SSL encryption. You will need to register with IBM, fill out a marketing survey, and accept the license agreement before downloading. The IBM HTTP Server requires glibc either version 2.0 or 2.1. glibc is the new Linux libc. If you have an older distribution that is based upon libc5, you will not be able to use the IBM HTTP Server. On an RedHat Package Manager (RPM)-based Linux distribution, you can run: <verb>rpm -qa | grep libc </verb> You will see output such as: <verb>glibc-2.1.2-11 libc-5.3.12-31 </verb> This will show you which versions of libc5 and glibc you have installed on your Linux distribution. In my above example I have both glibc and libc5 installed on my system. glibc is version 2.1, so I would want to download the files for glibc2.1. I suggest downloading all of the tar files for the glib version of Linux that you have as they are relatively small. However, minimally you will need the server file. For RedHat 6.0 and distributions derived from Redhat 6.0 you will also need the redhat60only. For glibc2.0 based distributions you will also need the libstdc file. <sect2>Installation <p> I suggest installing files in the /usr/local directory. After downloading the files, run: <verb>mkdir /usr/local/ibm mv HTTPServer.linux.* /usr/local/ibm </verb> You can now open the distribution package file or files. <verb>tar xvf [filename].tar </verb> Where [filename] is the name of the file. Under the /usr/local/ibm directory, you now should see the directory IHS. Use the RedHat Package Manager (RPM) to install the rpm files that the tar file produced. If you needed the libstdc file, you will need to install that file first. Then you would install the server RPM file such as: <verb>cd IHS rpm -i IBM_HTTP_Server-1.3.6-2.i386.rpm </verb> The above example shows version 1.3.6 for the Intel architecture. Substitute the filename as appropriate. After installing you can delete the rpm files as they can be easily recreated from the tar files. <sect2>Setting up Your Environment <p> The environment variables to set up are: <itemize> <item>PATH </itemize> The IBM HTTP Server installed itself into /opt/IBMHTTPServer. You need to add its bin directory to your PATH. <verb>export PATH=/opt/IBMHTTPServer/bin:$PATH </verb> Note that /opt/IBMHTTPServer/bin was added to the front of the PATH so that the installed Web Server will be used rather than any Web Server that might have come with your Linux distribution. To confirm that your PATH is correctly set up, check which Apache controller will be used. Type: <verb>which apachectl </verb> The output should reference apachectl in the /opt/IBMHTTPServer/bin directory. Note: because the IBM HTTP Server is based upon Apache, it uses the Apache controller to start and stop it. When you have both the IBM HTTP Server and Apache installed on a computer, take particular care to your PATH to make sure you are working with the correct server. You may need to modify the IBM HTTP Server configuration file. The configuration file was installed in /opt/IBMHTTPServer/conf/httpd.conf. The most common two entries that need to be changed are the ServerName and the Listen port number. Look for the key words &dquot;ServerName&dquot; and &dquot;Listen&dquot; in the httpd.conf file. The ServerName should be set to either your hostname or IP address. If your computer uses DHCP to acquire an IP address, the hostname is a better candidate. However, in order to use your computer's hostname, your computer's hostname and IP address must be properly registered in DNS. Additionally if you are running another Web server on the computer you need to assign the IBM HTTP Server to another port so you can run both Web servers simultaneously if necessary. The following is an example entry in httpd.conf. <verb>ServerName 192.168.0.4 Listen 3000 </verb> <sect2>Confirming Your Installation <p> To start the IBM HTTP Server, type the following: <verb>/opt/IBMHTTPServer/bin/apachectl start </verb> To confirm that the IBM HTTP Server is installed and running on your computer, open your web browser, and enter the URL: &dquot;http://192.168.0.4:3000&dquot; substituting the correct IP address and port number entered into httpd.conf. You should see a web page to the effect of &dquot;Welcome to the IBM HTTP Server&dquot;. Contratulations, you have installed, set up an environment for, and tested the IBM HTTP Server for Linux. <sect2>More Information <p> For more information, I suggest you look into the IBM HTTP Server Support page at <htmlurl url="http://www-4.ibm.com/software/webservers/httpservers/support.html" name="http://www-4.ibm.com/software/webservers/httpservers/support.html">. <sect1>Jetty HTTP Server and Servlet Container <label id="sec: jetty"> <p> <sect2>Background <p> Jetty is an Open Source HTTP Servlet Server written in 100% Java. It is both a full featured HTTP/1.1 server and a Servlet Container. It is designed to be light weight, high performance, embeddable, extensible and flexible, thus making it an ideal platform for serving dynamic HTTP requests from any Java application. <p> Jetty can be used as a stand-alone HTTP server and servlet container or it can be embedded in another java application (eg. the JBoss EJB container is using Jetty as it's prefered server and container solution). <p> As a combined server and servlet container, both these functions run efficiently in a single unix process. Installation and configuration is also simpler as a single application. <p> <sect2>Download <p> The Jetty HTTP Server and Servlet container may be downloaded via: <p> <htmlurl url="http://jetty.mortbay.org" name="http://jetty.mortbay.org">. <p> Jetty is distributed under the artistic license, full source is included and it can be used and distributed commercially. <p> <sect2>Installation <p> The package is distributed as a gzipped tar file, which can be unpacked with: <verb>gunzip < Jetty-x.x.x.tgz | tar xf - </verb> Which will create a Jetty-x.x.x directory where x.x.x is the version number. <p> To run the demo server: <verb>export JETTY_HOME=<jetty install directory> export JAVA_HOME=<JRE install directory> $JETTY_HOME/bin/jetty.sh run </verb> Then to see the Jetty demo and tutorial point a browser at <htmlurl url="http://localhost:8080" name="http://localhost:8080">. <p> Jetty can also be installed and run via JMX or as part of the JBoss distributions. See <htmlurl url="http://jetty.mortbay.org" name="http://jetty.mortbay.org"> or the README.TXT file for more details. <sect>How to Setup Java Servlet Support <label id="sec: servlet"> <p> There are several Web Server plug-ins and Application Servers available for Linux that provide support for Java Servlets. These include: <itemize> <item><ref id="sec: jrun" name="Allaire JRun"> <item><ref id="sec: jserv" name="Apache Tomcat"> <item><ref id="sec: weblogicservlet" name="BEA WebLogic"> <item><ref id="sec: enhydra" name="Enhydra"> <item><ref id="sec: locomotive" name="Locomotive"> <item><ref id="sec: websphere" name="IBM Websphere "> <item><ref id="sec: jettyservlet" name="Jetty"> </itemize> <sect1>Allaire JRun<label id="sec: jrun"> <p> To be written. See <htmlurl url="http://www.allaire.com/products/jrun/" name="http://www.allaire.com/products/jrun/">for more information. <sect1>Apache Tomcat <label id="sec: jserv"> <p> <sect2>Background <p> JServ has been replaced with Tomcat from the Apache Jakarta project: <htmlurl url="http://jakarta.apache.org/" name="http://jakarta.apache.org/">. This section is still written for JServ and needs to be updated. <p> Apache JServe is a 100% pure Java servlet engine fully compliant with the Java Servlet 2.0 specification. Apache JServ is part of the Java Apache Project. (From the Apache Java Project website). <sect2>Download <p> Apache JServ can be obtained from <htmlurl url="http://java.apache.org/jserv/index.html" name="http://java.apache.org/jserv/index.html">. >From the Apache JServ Project home page, follow the Download Apache JServ link. Currently RPM distributions are available for RedHat Linux. For other Linux distributions you will have to build from source. The following example describes how install the RPM for RedHat 6x. As of the time of this writing, the current version is 1.1b3. <sect2>Installation <p> I suggest installing files in the /usr/local directory. After downloading the files, run: <verb>mkdir /usr/local/apachejserv mv ApacheJServ*.rpm /usr/local/apachejserv </verb> For RedHat and RedHat-derived distributions, use the RedHat Package Manager (RPM) to install the rpm file such as: <verb>rpm -i ApacheJServ-1.1-b2_RH6x.i386.rpm </verb> The above example shows version 1.1-b2 for the RedHat 6x on the Intel architecture. <sect2>Setting up Your Environment <p> You will need to stop, set your Java environment variables, and restart Apache to register Apache JServ. To stop Apache, type: <verb>cd /etc/rc.d/init.d ./httpd stop </verb> Note: The httpd script used at boot time may be in a different location on other Linux distributions To set you Java environment, see the How to Install the JDK section of this document, specifically for the JDK you intend to use. You need to set several properties in the jserv.properties file installed in /etc/httpd/conf/jserv. Specifically, look for: <itemize> <item>wrapper.bin - to reference the JDK you installed <item>wrapper.classpath - to minimally include /usr/lib/apache/ApacheJServ.jar and /home/httpd/classes/servlet-2.0.jar <item>bindaddress=localhost <item>port=8007 </itemize> To restart Apache, type: <verb>cd /etc/rc.d/init.d ./httpd start </verb> <sect2>Confirming Your Installation <p> To confirm that the Apache JServ is installed and running on your computer, open your web browser, and enter the URL: &dquot;http://127.0.0.1/servlet/IsItWorking&dquot; substituting the correct IP address if you are browsing from another machine. You should see a web page to the effect of &dquot;Yes, It's Working!&dquot;. Contratulations, you have installed, set up an environment for, and tested the Apache JServ for Linux. For more assistance, I suggest you look into the Apache JServ website at <htmlurl url="http://java.apache.org/jserv/index.html" name="http://java.apache.org/jserv/index.html">. Now, to compile and run your own servlet. Enter the following Java servlet program. <verb>import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorldServlet extends HttpServlet { public void service (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } } </verb> <sect2>More Information <p> For more information, I suggest you look into the Java Apache Project website at <htmlurl url="http://java.apache.org/" name="http://java.apache.org/">. <sect1>BEA WebLogic <label id="sec: weblogicservlet"> <p> See <ref id="sec: weblogic" name="BEA WegLogic ">below. <sect1>Enhydra<label id="sec: enhydra"> <p> To be written. See <htmlurl url="http://www.enhydra.org" name="http://www.enhydra.org">for more information. <sect1>IBM WebSphere <label id="sec: websphere"> <p> To be written. See <htmlurl url="http://www-4.ibm.com/software/webservers/appserv/linux.html" name="http://www-4.ibm.com/software/webservers/appserv/linux.html">for more information. <sect1>Locomotive<label id="sec: locomotive"> <p> To be written. See <htmlurl url="http://www.locomotive.org/" name="://www.locomotive.org/">for more information. <sect1>Jetty<label id="sec: jettyservlet"> <p> The Jetty HTTP server is a combined server and servlet container. Installation of the HTTP server (see above) provides servlet support. More information can be obtained via the demo server and tutorial installed with the HTTP server. <p> <sect>How to Setup Java Server Pages (JSP) Support<label id="sec: jsp"> <p> To be written. <sect1>Apache Jakarta<label id="sec: jakarta"> <p> To be written. See <htmlurl url="http://jakarta.apache.com/" name="://jakarta.apache.com/">for more information. <sect1>Caucho Resin<label id="sec: resin"> <p> To be written. See <htmlurl url="http://www.caucho.com/" name="://www.caucho.com/">for more information. <sect1>Jetty<label id="sec: jettyjsp"> <p> The Jetty HTTP server comes with the Jasper JSP engine. Installation of the HTTP server (see 3.4 above) provides JSP support. More information can be obtained via the demo server and tutorial installed with the HTTP server. <p> <sect>How to Setup JDBC Support <label id="sec: jdbc"> <p> There are several databases that run on Linux that also support a JDBC interface. These include: <itemize> <item><ref id="sec: db2" name="IBM DB2 "> <item><ref id="sec: minisql" name="MiniSQL "> <item><ref id="sec: mysql" name="MySQL "> <item><ref id="sec: oracle" name="Oracle "> <item><ref id="sec: postgresql" name="PostgreSQL "> <item><ref id="sec: sybase" name="Sybase "> </itemize> If you are going to try just one DBMS, I suggest you initially try PostgreSQL, principally because it comes with most major Linux distributions and may already be installed on your system. <sect1>IBM DB2 <label id="sec: db2"> <p> To be written. See <htmlurl url="http://www-4.ibm.com/software/data/db2/linux/" name="http://www-4.ibm.com/software/data/db2/linux/">for more information. <sect1>MiniSQL <label id="sec: minisql"> <p> To be written. See <htmlurl url="http://www.hughes.com.au/" name="http://www.hughes.com.au/">for more information. <sect1>MySQL <label id="sec: mysql"> <p> To be written. See <htmlurl url="http://www.mysql.org/" name="http://www.mysql.org/">for more information. <sect1>Oracle <label id="sec: oracle"> <p> To be written. See <htmlurl url="http://platforms.oracle.com/linux/" name="http://platforms.oracle.com/linux/"> <sect1>PostgreSQL <label id="sec: postgresql"> <p> <sect2>Background <p> PostgreSQL is a sophisticated Object-Relational DBMS, supporting almost all SQL constructs, including subselects, transactions, and user-defined types and functions. It is the most advanced open-source database available anywhere. Commercial Support is also available from PostgreSQL, Inc. The current version is 6.5.3 and is available at any of the many mirror sites or on CD. (From the PostgreSQL website.) PostgreSQL may have already been shipped with your Linux distribution because of its open source license. <sect2>Download and Installation <p> Rather than downloading from PostgreSQL, I suggest you initially try the PostgreSQL that most likely came with your Linux distribution. Alternatively, PostgreSQL can be obtained from <htmlurl url="http://www.postgresql.org" name="http://www.postgresql.org">. To confirm that PostgreSQL is installed on your computer, type: <verb>rpm -qa | grep postgresql </verb> or <verb>which postmaster which psql </verb> You need the postgresql, postgresql-server, and postgresql-java packages installed to use Java with PostgreSQL. Make sure PostgreSQL is running. Type: <verb>ps -f -u postgres </verb> You should see postmaster, the PostgreSQL daemon, running. If postmaster is not running, there will probably be a Sys V Init script that you can use to start it. In many distributions it is located in /etc/rc.d/init.d. To start PostgreSQL, type: <verb>cd /etc/rc.d/init.d ./postgresql start </verb> You can use the above &dquot;ps&dquot; command to confirm that PostgreSQL is running. Note: To use JDBC, PostgreSQL needs to have been started with the '-i' parameter indicating support for TCP/IP connections rather than solely UNIX domain sockets. Confirm that postmaster> was started with the '-i' paramter. Create a test database by typing: <verb>su - postgres createdb javatest </verb> You should see no error messages. Create a test table with one test row. First, log in to the interactive PostgreSQL tool and connect to the javatest database you just created by typing (as the postgres user): <verb>psql javatest </verb> You should see confirmation that you are connected to the database: javatest. Then, create the test table by typing (within psql): <verb>create table test (col1 varchar(255)); </verb> You should see the &dquot;CREATE&dquot; confirmation message. Next, insert one row by typing (within psql): <verb>insert into test (col1) values ('Hello, from PostgreSQL!'); </verb> You should see the &dquot;INSERT&dquot; confirmation message. Finally, confirm that the row is there by typing (within psql): <verb>select col1 from test; </verb> You should see the row you just created. You can exit psql by typing &dquot;\ q&dquot;. For more assistance on working with PostgreSQL, I suggest you look into the Database-SQL-RDBMS HOW-TO document for Linux (PostgreSQL Object Relational Database System) at <htmlurl url="http://metalab.unc.edu/mdw/HOWTO/PostgreSQL-HOWTO.html" name="http://metalab.unc.edu/mdw/HOWTO/PostgreSQL-HOWTO.html">. You will need to add the appropriate JAR to your CLASSPATH. The PostgreSQL JARs come in the <em>postgresql-jdbc</em> package. <verb>export CLASSPATH=$CLASSPATH:/usr/lib/pgsql/jdbc6.5-1.2.jar </verb> You may need to substitute the path depending you where PostgreSQL is installed on your system. <sect2>Confirming Your Installation <p> You are now ready to compile and run a simple JDBC application that uses PostgreSQL. Create the following program. <verb>import java.sql.*; class PostgreSQLTest { public static void main (String[] args) { try { Driver driver = (Driver) Class.forName(&dquot;postgresql.Driver&dquot;).newInstance(); DriverManager.registerDriver(driver); String url = &dquot;jdbc:postgresql:javatest&dquot;; Connection con = DriverManager.getConnection(url, &dquot;postgres&dquot;, &dquot;&dquot;); Statement stm = con.createStatement(); stm.setQueryTimeout(10); ResultSet rs = stm.executeQuery(&dquot;select col1 from test&dquot;); rs.next(); System.out.println(rs.getString(1)); } catch (SQLException e) { System.out.println(&dquot;Exception!&dquot;); System.out.println(e.toString()); } } </verb> Compile the program with the Java compiler. <verb>javac PostgreSQLTest.java </verb> If the compiler produces errors, double check the syntax and confirm your PATH and CLASSPATH. Run the program with the JVM. <verb>java PostgreSQLTest </verb> If the JVM produces errors, confirm your PATH and CLASSPATH. You should see the following output: <verb>Hello, from PostgreSQL! </verb> Congratulations, you have installed, set up an environment for, and tested a JDBC interface to PostgreSQL. <sect2>More Information <p> For more information, I suggest you look into the PostgreSQL website at <htmlurl url="http://www.postgresql.org/" name="http://www.postgresql.org/">. <sect1>Sybase <label id="sec: sybase"> <p> <sect2>Background <p> Sybase Adaptive Server Enterprise is a commericial RDBMS that is available for the Linux operating system. While Sybase has recently released version 12.0, version 11.9.2 is available for Linux. According to the Sybase website, &dquot;By porting ASE to Linux, Sybase provides the Linux development community with the first highly scalable, high-performance database engine available for the platform. The package includes the standard features of Adaptive Server Enterprise and all related connectivity components. Adaptive Server Enterprise 11.9.2 is offered FREE for development.&dquot; <sect2>Download <p> The Sybase ASE can be obtained from <htmlurl url="http://www.sybase.com/products/databaseservers/linux/linux1192_reg.html" name="http://www.sybase.com/products/databaseservers/linux/linux1192_reg.html">. In order to download, you will have to register with the Sybase website and agree to the license online. The Sybase JDBC driver can be obtained from <htmlurl url="http://www.sybase.com/products/internet/jconnect/" name="http://www.sybase.com/products/internet/jconnect/">. Select download jConnect 4.2/5.2. If you have access to a Sybase server on the network, you only need to download and install the JDBC driver. <sect2>Installation <p> Installation of Sybase is beyond the scope of this HOWTO. This HOWTO will assume that Sybase has been correctly installed and configured and that you can get to Sybase using isql. Log into isql as sa and create a test user and test database by typing: <verb>create database javatest go sp_addlogin javatest, javatest, javatest go use javatest go sp_dbowner javatest go </verb> You should see no error messages. Create a test table with one test row. First, log in to isql as the javatest user and type: <verb>create table test (col1 varchar(255)) go </verb> You should see no error messages. Next, insert one row by typing: <verb>insert into test (col1) values ('Hello, from Sybase!') go </verb> You should see no error messages. Finally, confirm that the row is there by typing: <verb>select col1 from test go </verb> You should see the row you just created. You can exit isql by typing &dquot;exit&dquot;. For more assistance on working with Sybase, review the documentation that can be downloaded with Sybase. You will need to add the appropriate JAR to your CLASSPATH. <verb>export CLASSPATH=$CLASSPATH:/usr/local/sybase/jConnect-5_2/classes/jconn2.jar </verb> You may need to substitute the path depending you where jConnect is installed on your system. <sect2>Confirming Your Installation <p> You are now ready to compile and run a simple JDBC application that uses Sybase. Create the following program. <verb>import java.sql.*; class SybaseTest { public static void main (String[] args) { try { Driver driver = (Driver) Class.forName(&dquot;com.sybase.jdbc2.jdbc.SybDriver&dquot;).newInstance(); DriverManager.registerDriver(driver); String host = &dquot;127.0.0.1&dquot;; String port = &dquot;4100&dquot;; String url = &dquot;jdbc:sybase:Tds:&dquot; + host + &dquot;:&dquot; + port; Connection con = DriverManager.getConnection(url, &dquot;javatest&dquot;, &dquot;javatest&dquot;); Statement stm = con.createStatement(); stm.setQueryTimeout(10); ResultSet rs = stm.executeQuery(&dquot;select col1 from test&dquot;); rs.next(); System.out.println(rs.getString(1)); } catch (SQLException e) { System.out.println(&dquot;Exception!&dquot;); System.out.println(e.toString()); } } </verb> You will need to substitute the host and port number of you Sybase server as appropriate. See $SYBASE/interfaces and the $DSQUERY entry for what values to use for the host and port number. Compile the program with the Java compiler. <verb>javac SybaseTest.java </verb> If the compiler produces errors, double check the syntax and confirm your PATH and CLASSPATH. Run the program with the JVM. <verb>java SybaseTest </verb> If the JVM produces errors, confirm your PATH and CLASSPATH. You should see the following output: <verb>Hello, from Sybase! </verb> Congratulations, you have installed, set up an environment for, and tested a JDBC interface to Sybase. <sect2>More Information <p> For more information, I suggest you look into the Sybase jConnect website at <htmlurl url="http://www.sybase.com/products/internet/jconnect/" name="http://www.sybase.com/products/internet/jconnect/">. <sect>How to Setup Enterprise Java Bean (EJB) Support <label id="sec: ejb"> <p> To be written. <sect1>BEA WebLogic <label id="sec: weblogic"> <p> To be written. See <htmlurl url="http://www.beasys.com/linux/" name="http://www.beasys.com/linux/">for more information. <sect1>EJBoss<label id="sec: ejboss"> <p> <sect2>Background <p> EJBoss has been renamed JBoss and is well advanced with stable J2EE compliant releases at <htmlurl url="http://www.jboss.org/" name="http://www.jboss.org/">. <p> This section was written when it was still EJBoss 0.95 and needs to be updated. <sect2>Download <p> JBoss can be downloaded from the JBoss website at <htmlurl url="http://www.jboss.org/" name="http://www.jboss.org/">. <sect2>Installation <p> I suggest installing files in the /usr/local directory. After downloading, run: <verb>mkdir /usr/local/ejboss mv ejboss* /usr/local/ejboss </verb> Unjar the file: <verb>jar xvf ejboss095_jdk122.jar </verb> You should see various files and directories created under /usr/local/ejboss. The above example shows EJBoss 0.95 for JDK 1.2.2. Substitute the file names as appropriate. <sect2>Setting up Your Environment <p> The environment variables to set up are: <itemize> <item>CLASSPATH </itemize> The CLASSPATH environment variable references all JARs and directories that you will need to compile and run Java programs. Include the EJBoss JAR and the beans/generated directory in your CLASSPATH. <verb>export CLASSPATH=/usr/local/ejboss/lib/ejboss095_jdk122.jar:/usr/local/ejboss/beans/generated:$CLASSPATH </verb> <sect2>Confiming Your Installation <p> You are now ready to compile and run a simple EJB application. Create the following three source files for the server. First, the business interface. <verb>// EJBTest.java import javax.ejb.*; import java.rmi.RemoteException; public interface EJBTest extends EJBObject { public String greet() throws RemoteException; } </verb> Second, the home interface. <verb>// EJBTestHome.java import javax.ejb.*; import java.rmi.RemoteException; public interface EJBTestHome extends EJBHome { public EJBTest create() throws CreateException, RemoteException; } </verb> Third, the bean implementation class. <verb>// EJBTestBean.java import javax.ejb.*; import java.rmi.RemoteException; public interface EJBTestBean implements SessionBean { private SessionContext mContext = null; public void ejbPassivate() { System.out.println(&dquot;EJBTestBean passivated.&dquot;); } public void ejbActivate() { System.out.println(&dquot;EJBTestBean activated.&dquot;); } public void ejbCreate() { System.out.println(&dquot;EJBTestBean created.&dquot;); } public void ejbRemove() { System.out.println(&dquot;EJBTestBean removed.&dquot;); } public void setSessionContext() { System.out.println(&dquot;EJBTestBean context set.&dquot;); mContext = context; } public String greet() { return &dquot;Hello, I'm an EJB!&dquot;; } } </verb> Compile the server source files with the Java compiler: <verb>javac EJBTest*.java </verb> If the compiler produces errors, double check the syntax and confirm your PATH and CLASSPATH. Now that you have successfully written and compiled the server source files, you need to deploy your bean to EJBoss. Deploying a bean to EJBoss requires several steps that must be performed exactly. First, create the file ejb-jar.xml. <verb><?xml version=&dquot;1.0&dquot; encoding=&dquot;Cp1252&dquot;?> </verb> <verb> </verb> <verb><ejb-jar ID=&dquot;&dquot;> </verb> <verb> <description></description> </verb> <verb> <display-name></display-name> </verb> <verb> <small-icon></small-icon> </verb> <verb> <large-icon></large-icon> </verb> <verb> <ejb-client-jar></ejb-client-jar> </verb> <verb> <enterprise-beans> </verb> <verb> <session> </verb> <verb> <description>Nextgen bean</description> </verb> <verb> <ejb-name>nextgen.EJBTest</ejb-name> </verb> <verb> <home>EJBTestHome</home> </verb> <verb> <remote>EJBTest</remote> </verb> <verb> <ejb-class>EJBTestBean</ejb-class> </verb> <verb> <session-type>Stateful</session-type> </verb> <verb> <transaction-type>Bean</transaction-type> </verb> <verb> <env-entry> </verb> <verb> <description></description> </verb> <verb> <env-entry-name></env-entry-name> </verb> <verb> <env-entry-type>java.lang.String</env-entry-type> </verb> <verb> <env-entry-value></env-entry-value> </verb> <verb> </env-entry> </verb> <verb> <resource-ref> </verb> <verb> <description></description> </verb> <verb> <res-ref-name></res-ref-name> </verb> <verb> <res-type></res-type> </verb> <verb> <res-auth>Container</res-auth> </verb> <verb> </resource-ref> </verb> <verb> </session> </verb> <verb> </enterprise-beans> </verb> <verb> <assembly-descriptor /> </verb> <verb> </ejb-jar> </verb> The above file, which must be named ejb-jar.xml identifies the interface and class names of files that you just created as well as a name for the object. Second, relative to the directory of the three class files you just created, create a META-INF directory. <verb>mkdir META-INF mv ejb-jar.xml META-INF </verb> Third, package all four files into a jar. <verb>jar cvf EJBTest.jar EJBTest*.class META-INF/ejb-jar.xml </verb> You should see that it added the manifest as well as the three class files and the XML deployment descriptor file. Fourth, put the JAR you just created in the EJBoss beans directory. <verb>mv EJBTest.jar /usr/local/ejboss/beans </verb> Fifth, move the class files you created to the EJBoss beans/generated directory. <verb>mv EJBTest*.class /usr/local/ejboss/beans/generated </verb> (This fifth step is redudant due to a bug in EJBoss 0.95. ) You are now ready to start the EJBoss server. cd /usr/local/ejboss sh server.sh You should see the proxy files compile automatically and confirmation that your EJB is deployed. You are now ready to write, compile and test the simple client applicaiton. <sect1>Bullsoft JOnAS EJB <label id="sec: jonas"> <p> To be written. See <htmlurl url="http://www.bullsoft.com/ejb/" name="http://www.bullsoft.com/ejb/">for more information. </article>