Archive for January, 2009

Chapter 3: Tomcat Installation The Tomcat Installation Directory

Saturday, January 24th, 2009

Chapter 3: Tomcat Installation The Tomcat Installation Directory After your install Tomcat, you should see the directory structure shown in Figure 3-9 . Figure 3-9: Tomcat 6 directory structure As you can see, there are differences between the Tomcat 6 directory structure and that of older Tomcat versions: . Tomcat 5.5 and earlier Tomcat versions have shared, common, and server directories under the Tomcat install directory. The /shared directory is to be used by Web applications that want to share classes and JAR files with each other; the /commondirectory contains class files and JAR files that were visible to both the Tomcat server, as well as all deployed Web applications. The /server directory, on the other hand, contains classes and JAR files visible only to Tomcat. . Tomcat 6 does not have these directories. Instead, it has a lib directory ( /lib), where all the JAR files used by Tomcat go. This is visible to all Web applications, too; however, Web application specific JAR files should not be placed here. This directory structure is explained in greater detail in the next chapter, but briefly, the different directories are: . bin: The bin directory contains the shell scripts and batch files for starting Tomcat in various modes. It also includes a pre-compiler for JSP pages that can improve startup time and first-time response (the time it takes for the server to respond to a request for a JSP page that has not been previously compiled). Compilation occurs only once, but it can frustrate the first visitor to a site after the server is restarted because of the long response time. . conf: The conf directory contains the configuration files for Tomcat. These include general server configuration files, a default user list for file-based authentication and security for

For high quality website hosting services please check cheap web hosting website.

Chapter 3: Tomcat Installation Subversion Repository Tomcat, like

Friday, January 23rd, 2009

Chapter 3: Tomcat Installation Subversion Repository Tomcat, like a lot of other Apache projects, has migrated from using CVS as its version control system to Subversion. Subversion is designed to be a replacement of CVS, and overcomes a lot of the deficiencies that CVS had. More information on Subversion, including downloads of clients and servers, is available at http://subversion.tigris.org/. A popular Windows client for Subversion is Tortoise SVN (http://tortoisesvn.tigris.org/), which integrates into Windows Explorer. The commands shown here, however, are for a Linux-based, command-line client. $ svn co http://svn.apache.org/repos/asf/tomcat container In the preceding command, the URL ( http://svn.apache.org/repos/asf/tomcat ) specifies the root of the Tomcat Subversion repository, and containeris the module being checked out. If you are familiar with the CVS version control system, you can think of the Subversion repository root URL as analogous to CVSROOT. However you can browse the root URL using any Web browser, and view the code without downloading it. You can do neat stuff like this because the Subversion server makes use of the Apache HTTP server, and a WebDAV (www.webdav.org/) module. Subversion has a standalone server, too, just as CVS does, but the Apache/WebDAV combination is more commonly used. The container module contains the core Tomcat code; the list of all other modules is at http://tomcat .apache.org/svn.html. Building a Source Release Once you have downloaded the source code, building Tomcat is a simple matter of running the Ant build script present in the top-level directory. Ant is a build utility for Java programs. If you are not familiar with using it, refer to Appendix B . The commands that follow assume that both Java (/bin ) and Ant ( /bin ) are defined in the system PATH. $ cd apache-tomcat-6-x-y $ ant The Ant build script (build.xml) specifies which third-party jar files are to be downloaded, and as the script executes, you will see the required components either downloaded as required, or checked out from CVS repositories not all Apache projects have been migrated to Subversion at the time of this writing. Naturally, the machine that the build is run on requires Internet access, as well as a command- line CVS client. If not, you will see errors during the build process. If the machine that you are running the build on connects to the Internet through a proxy server, you have to specify this in a build .properties file. Copy the sample file from the apache-tomcat-6 directory to the parent directory, rename it to build.properties, and edit the following lines as required: # —– Proxy setup —-proxy. host=proxy.domain proxy.port=8080 proxy.use=on

If you looking for unlimited one inclusive web hosting plan please check web hosting plan website.

Chapter 3: Tomcat Installation You can find this

Friday, January 23rd, 2009

Chapter 3: Tomcat Installation You can find this entry by searching for the string port= 8080 . Changing this to another number (higher than 1024 in Linux) will change the Tomcat port number. Changing it to 80 will enable you to connect to Tomcat using the URL http://localhost, providing that the Tomcat server is started with root permissions. The reason for running Tomcat as root is that on Unix (and Linux) systems, non-root processes cannot bind to ports lower than 1024. However, running Tomcat as the super user is a very bad idea, because any badly written (from a security perspective) Web application can compromise your system. If you want Tomcat to listen on port 80, there are a number of other, more secure alternatives to running it as root: . Run Apache Web server on port 80 and configure Apache to send requests to Tomcat. (Chapter 11 discusses this in more detail.) However, this solution just pushes the problem over to Apache because now Apache has to deal with how to bind to port 80 without running as root. . Run Tomcat on a non-privileged port, such as 8080 and use a port redirector such as rinetd to redirect messages coming to port 80 to port 8080. . Run Tomcat on a non-privileged port, such as 8080 and configure the firewall to redirect external requests to port 80 to the internal port 8080. Because production Web sites almost always have a firewall in deployment, this is often the most commonly used procedure. If you have any problems installing, refer to the Troubleshooting and Tips section at the end of this chapter. Building Tomcat from Source While downloading Tomcat from the Apache Web site, you can see that both source codes as well as binary versions of Tomcat are available. This section explains how (and why) you would build and install Tomcat from source. Do You Need to Build Tomcat from the Source Code? The short answer is no. If you are an administrator trying to install a production-ready release of Tomcat, you almost never would need to download and build a source release of Tomcat. If this is the case, feel free to skip this section and move on to the next major section in the chapter, The Tomcat Installation Directory. You would want to download a source release if you are developer who wants to experiment with Tomcat, perhaps even extend it. Or, if you have a bug in your particular Tomcat version, and you want to download the fix for it and patch it in, without waiting for the next official release. In the second case, you would be downloading the patch from the Tomcat Subversion repository. Downloading the Source Release The simplest way to get a source release is to download a labeled release from the Tomcat download site (http://tomcat.apache.org). The usual caveat of verifying the release (MD5 checksum, PGP signature) applies in this case, too. These releases are usually labeled as apache-tomcat-6.x.y.tar.gzor apache-tomcat.6.x.y.zip.

If you looking for unlimited one inclusive web hosting plan please check unlimited web hosting website.

Chapter 3: Tomcat Installation Path on Gentoo Standard

Thursday, January 22nd, 2009

Chapter 3: Tomcat Installation Path on Gentoo Standard Tomcat Path /usr/share/tomcat-x.y/bin /usr/share/tomcat-x.y/common /etc/tomcat-x.y /var/log/tomcat-x.y /usr/share/tomcat-x.y/server /var/lib/tomcat-x.y/shared /usr/share/tomcat-x.y/lib /var/tmp/tomcat-x.y /var/lib/tomcat-x.y/webapps /var/run/tomcat-x.y /bin /common for Tomcat 5.5 and before; not present in Tomcat 6. /conf /logs /server for Tomcat 5.5 and before; not present in Tomcat 6. /shared for Tomcat 5.5 and before; not present in Tomcat 6. /lib for Tomcat 6. Not present in earlier versions, i.e., Tomcat 5.5 and before. /temp /webapps /work Tomcat installations on Gentoo Linux, a popular Linux distribution, have a different directory structure than standard Tomcat installations. Instead of using the Gentoo emerge command to install, administrators can install the standard Tomcat distribution as on other Linux distributions. Viewing the Default Installation To confirm that Tomcat is running, point your browser to the following URL: http://localhost:8080/ Choose the JSP Examples link from the menu on the left-hand side and select some of the examples to run. Confirm that they run without error messages. Do the same for the Servlet Examples to test their functionality. Modifying Port Numbers Tomcat uses port 8080 by default. Because the majority of server hardware already includes a standard Web server installation, usually Apache, Tomcat does not attempt to connect to the standard HTTP traffic port, 80, by default. The configuration file that specifies the port number is called server.xmland can be found in the $CATALINA_HOME/conf directory. Somewhere within it you should find the following entry:

For high quality java hosting services please check tomcat web hosting website.

Chapter 3: Tomcat Installation As with the preceding

Wednesday, January 21st, 2009

Chapter 3: Tomcat Installation As with the preceding installation method, a new window will open, indicating that the server has started. To shut down Tomcat, type shutdown. Installing Tomcat on Linux Installing Tomcat on Linux or Unix is easy. Download the tar/gzip file of the latest Tomcat 6. x binary release from the following URL: http://tomcat.apache.org/ Extract the downloaded file onto your hard drive to a path such as /usr/java/jakarta-tomcat-6. Note that you should use the GNU version of the tar utility to ensure that long file names are handled properly. You should now export the $CATALINA_HOMEvariable, using the following command (in bash): # CATALINA_HOME=/usr/java/ tomcat-6 # export CATALINA_HOME The Tomcat 6 release notes also recommend that if you are on GLIBC 2.2 / Linux 2.4, you should define an additional environment variable as shown: # export LD_ASSUME_KERNEL=2.2.5 Also, if you are on Redhat Linux 9.0, you should use the following setting: export LD_ASSUME_KERNEL=2.4.1 These settings avoid known stability problems with Tomcat. You can check your glibc(i.e., the GNU C Library) version on Redhat using the rpm -q glibccommand. All these commands can be added to your ~/.bashrcor /etc/profileas you did for the JDK installation, or you can create a shell file, tomcat.sh, and place it in /etc/profile.d. It will be run automatically by /etc/profileat boot time to make the variable available to all users. You can now start Tomcat by running the following shell command: # $CATALINA_HOME/bin/startup.sh Another approach to installing Tomcat on Linux is to use the package manager tool specific to the Linux distribution, such as emergeon Gentoo Linux or apt-geton Debian to download and install. This is often a very convenient and familiar approach for administrators, and gives them a stable version of Tomcat to work with. However it should be noted that these tools may place Tomcat configuration files in non-standard places. The following table summarizes the differences between the standard Tomcat directory structure, and the one created by installing Tomcat using Gentoo s emerge command. In the rest of the book, we assume a standard Tomcat directory structure is in place. If you are using a Tomcat installed with the Gentoo conventions, use the table to map the directory paths appropriately.

For reliable and cheap web hosting services please check cheap web hosting website.

Chapter 3: Tomcat Installation addressed to port 22,

Tuesday, January 20th, 2009

Chapter 3: Tomcat Installation addressed to port 22, Telnet to 23, and so on. Browsers automatically point at port 80 if no port is specified (443 for HTTPS); hence, the use of ports is not immediately visible to the average user. Because the majority of server hardware already includes a standard Web server installation (usually Apache for Linux, and IIS for Windows), Tomcat does not attempt to connect to the standard HTTP traffic port (which is 80 by default), but rather to port 8080. The configuration file that specifies the port number is called server.xmland can be found in the installation folder of Tomcat in the %CATLINA_HOME%conf directory. It s just a text file, and somewhere within it you should find an entry similar to the following: You can find this entry by searching for the string port= 8080 . Changing this to another number will change the Tomcat port number. Changing it to 80 enables you to connect to Tomcat using the following URL without the trailing colon and port number: http://localhost/ If you have any problems, refer to the Troubleshooting and Tips section at the end of this chapter. Conversely, if all has gone well, you are now the proud owner of your own Tomcat instance. Before you are finished, you should check Tomcat s capability to serve JSP pages and servlets. To do this, choose the JSP Examples link from the left-hand menu and select some of the examples to run. Confirm that they all run as they are supposed to without error messages. Do the same for the Servlet Examples link to test this functionality. Installing Tomcat on Windows Using the ZIP File Installing Tomcat using the ZIP file is not much different from the process described earlier. The ZIP file is provided for those who prefer to manually install Tomcat. To install Tomcat using the ZIP file, simply unpack the contents of the file to your directory of choice, such as c:javatomcat-6.0. Now add the %CATALINA_HOME% environment variable as shown in the preceding directions. To check your installation, you need to follow slightly different instructions than before. Because the shortcuts for the server are not created automatically, you need to call a couple of batch files provided in the %CATALINA_HOME%bin directory for this purpose. To start the server, type the following at the command prompt: > cd %CATALINA_HOME%bin > startup.bat

For reliable and cheap web hosting services please check tomcat web hosting website.

Chapter 3: Tomcat Installation As you can see,

Monday, January 19th, 2009

Chapter 3: Tomcat Installation As you can see, the default is for no action to be taken. As you desire, you can configure the service to be restarted on failure, and/or run programs when a failure occurs. Viewing the Default Installation Tomcat, like most servers, comes with a default home page that can be used to confirm that the installation is working. Enter the following address in a browser: http://localhost:8080/ The page shown in Figure 3-8 should appear. Figure 3-8: The default Tomcat home page Assigning Port Numbers The default installation requires you to include the port number assignation (for example, :8080) in the server address. Ports are logical addresses in a computer that enable multiple communications with the server and the channeling of different protocols. For example, SMTP is addressed to port 25, SSH is

For high quality java hosting services please check tomcat web hosting website.

Chapter 3: Tomcat Installation To start the server,

Monday, January 19th, 2009

Chapter 3: Tomcat Installation To start the server, right-click the Tomcat entry and choose Start. No window will appear because the server is running as a service in the background. Once the server is started, the options for restarting and stopping the server will also be enabled. Changing Service Options Looking at Figure 3-6 , you can see that the Startup Type is set to Automatic, which means that restarting the computer also starts an instance of Tomcat automatically. From now on, every time Windows is started, Tomcat will automatically start up at boot time and will be available from then on. You can further customize the service by choosing the Properties option from the context menu. This enables the startup type to be changed to Manual, or for the service to be disabled entirely. It also enables you to choose to automatically restart the service should it crash. This last option is especially useful because not only does it allow you to reboot the computer, but it also enables you to run a script should the server fail. You can also perform different actions depending on how many times the service has failed (by choosing the Recovery tab), so you can initially request a reboot of the service, then a reboot of the machine, after which any subsequent failures will cause a script to run that perhaps alerts you of the failure. If you wish to set the recovery options, right-click the Tomcat service entry in the list and choose Properties. In the window that opens, choose Recovery, and you should be presented with the options shown in Figure 3-7 . Figure 3-7: The Recovery options

For reliable and cheap web hosting services please check javaweb hosting website.

Chapter 3: Tomcat Installation Figure 3-5: Starting Tomcat

Sunday, January 18th, 2009

Chapter 3: Tomcat Installation Figure 3-5: Starting Tomcat from the command line To shut down Tomcat, use the Shutdown shortcut (Start .Programs .Apache Tomcat 6 . Stop Tomcat) or type shutdown into the command prompt from Tomcat s bindirectory. Starting the Server as a Service If you wish to start the server as a service (and assuming you chose this option when installing Tomcat), you will need to start up the service. This is done by double-clicking Administrative Tools in the Control Panel. In Administrative Tools, you should select Services. In the window that opens, you should find an entry for Tomcat, as shown in Figure 3-6 . Figure 3-6: The Apache Tomcat service

For high quality jboss hosting services please check jboss web hosting website.

Chapter 3: Tomcat Installation A service is clearly

Saturday, January 17th, 2009

Chapter 3: Tomcat Installation A service is clearly the better option for production servers, but may not be what you want for development; starting and stopping a service repeatedly can be a pain. Finishing the Installation Once you ve chosen the components you wish to install, click the Next button. You will be prompted to choose a directory into which Tomcat should be installed. While the default directory is C:Program FilesApache Software FoundationTomcat 6.x, you should consider installing Tomcat into a path that does not contain spaces in the name, such as c:javatomcat-6.x. Once you ve reviewed the destination folder, click Next. The next screen requests the Tomcat port and an administrator login. Leave the port value as 8080, but choose a unique username for the administrator login, and select a hard-to-guess password. When you are done, click Next. The final screen will ask for the location of the JDK you installed earlier. Enter it if it was not automatically found. Then, click Install. Setting Environment Variables While not strictly required when Tomcat s Windows installer is used, it is a good idea to add an environment variable that points to the directory in which you installed Tomcat. The environment variable is named CATALINA_HOME. To add the environment variable, navigate to your Control Panel and choose System. Now choose the Advanced tab and select the Environment Variables button. Select the New button in the system variables (lower half) section and enter CATALINA_HOMEas the variable name and the path to your Tomcat installation (for example, c:javatomcat-6.0). Testing the Installation To test the installation, you must first start the server. You can start Tomcat manually or, if you installed Tomcat as a service, you can start the service. Starting the Server Manually You can start the server manually by selecting Start . Programs .Apache Tomcat 6 and choosing Start Tomcat. A new command-prompt window will appear, demonstrating that the server is running. Alternatively, you can start Tomcat by opening a command-prompt window, navigating to bin, and typing tomcat6.exe, as shown in Figure 3-5 . The standard Tomcat startup script (startup.bat) is not present when installing from the installer. If Tomcat does not start up, you can find some troubleshooting tips at the end of this chapter. You may also get error messages if your %JAVA_HOME%variable is not defined, and if the %JAVA_HOME%bindirectory within the JDK is not in the PATH. If this is the case, you will get an error message such as the following: java is not recognized as an internal or external command, operable program or batch file. Refer to the instructions in the section Installing the Java Virtual Machine, earlier in this chapter, if this is the case.

For reliable and cheap web hosting services please check cheap web hosting website.