Tomcat Free Installation Configuration 2

Source: Internet
Author: User

Tomcat is an excellent Jsp/servlet container that was originally developed by Sun and later contributed to the Apache community. Tomcat now has a version of 6. TOMCAT6 implements the Servlet2.5 and JSP2.1 specifications. More new features are available for Web development and Web services. This article uses a version of Tomcat6.0.14, which requires a minimum of 1.5 jdk versions. There are differences in the configuration between Tomcat versions, and if the reader is using a different version, please read the official Tomat documentation carefully, or search the Web for relevant information.

Tomcat has two versions of the installation version and the release version, in addition to providing a graphical interface in the background and Windows services, the other uncompressed version of no difference. I use a compressed version.

The first step, we need to download Tomcat, is http://tomcat.apache.org. After the download is complete, unzip, my Tomcat is located under D:\softer\tomcat, the following is used to represent this directory $tomcat.


First, configure the environment variables (if you use myeclipse development without configuring the environment variables, directly in the MyEclipse configuration can be):

Here are the specific settings for the environment variables
Variable Name variable value
Tomcat_home = Tomcat root directory such as: D:\tomcat


Catalina_base = The root directory of Tomcat


Catalina_home = The root directory of Tomcat


Parsing of variable names:
The Catalina.home and Catalina.base properties save disk space only when you need to install multiple Tomcat instances instead of installing multiple software backups.
In Tomcat6.0, for example, its Tomcat directory structure is as follows:


Bin (Run script)
Conf (config file)
LIB (Core library file)
Logs (log directory)
Temp (temp directory)
WebApps (Directory of auto-loaded applications)
Work (JVM temp file directory [Java.io.tmpdir])
Let's look at these directories that can be shared by multiple Tomcat instances, in fact only the bin and Lib directories, other directories conf, logs, temp, webapps, and work each Tomcat instance must have its own independent backup.
Understanding these relationships makes it easy to understand the use of catalina.home and catalina.base.
The location where catalina.home points to the common information is the parent directory of Bin and Lib.
Catalina.base points to the location of private information for each Tomcat directory, which is the parent directory for conf, logs, temp, webapps, and work.
When you run only one Tomcat instance, the two properties point to the same location

Simply put, Catalina_home is the installation directory for Tomcat, and Catalina_base is the working directory of Tomcat. If we want to run multiple instances of Tomcat, but do not want to install multiple Tomcat software replicas. Then we can configure multiple working directories, each running instance exclusive to a working directory, but share the same installation directory.

If we want to run another Tomcat instance, we can create a directory where conf, logs, temp, WebApps, work are copied to the directory, and then Catalina_base point to that directory.

Tomcat_home is for the sake of configuring environment variables for convenience


Classpath
.; %tomcat_home%\lib\servlet-api.jar;%tomcat_home%\lib\jsp-api.jar;
"." means that the current path is generally fitted with a JDK configured with the path to add "." To the classpath. You can compile the Java file.
The two jar packages under%tomcat_home%\lib\ are key APIs without them you write a servlet that has no way to compile so be sure to.

$TOMCAT \ Bin Below is a script that is used by TOMCAT, which is a batch file for the Windows platform with the name extension. SH, which is a script for Linux or UNIX platforms. What we usually use is the startup.bat,shutdown.bat script. We can also use Catalina.bat start to start Tomcat, Catalina.bat stop to close Tomcat, in fact,Startup.bat is the alias of Catalina.bat start, Similarly Shutdownup.bat is the alias of Catalina.bat stop .

Catalina.bat is the core script that operates Tomcat, and you can view the parameters and their descriptions that Catalina can use by Catalina–help. Double-click startup.bat to start Tomcat, after starting Tomcat, we enter the following URL: http://localhost:8080/, if you see the Tomcat page, prove the installation success, if not successful, Check to see if the correct version of JAVA_HOME,JDK is set too low. If this is still unsuccessful, there may be a port conflict, and the following describes how to modify the port number.

Second, inside the MyEclipse configuration Tomcat6

Menu above: "Window"--"Preferences"-

enter "Tomcat"-Select the location for Tomcat, tick "enable" to click OK or ApplyServer-->tomcat6.x-->start can be started

Console display start time

Enter the address in the browser to see a kitten


Third, tomcat other configuration

$TOMCAT \conf is the configuration file for TOMCAT, the most important configuration file is servler.xml. The Server.xml can be re-specified by catalina.bat–config, such as specifying CONFIG. * Instead of Servler.xml, with the following command:

Catalina.bat Run–config Conf\config.xml

Server.xml can configure all the information needed to deploy the application, starting with TOMCAT5, the application configuration can be isolated from server.xml, which is one of the benefits that Tomcat now recommends for configuration, which is obvious and easier to maintain. Another benefit is that the change in Servler.xml can only be done by restarting Tomcat, and after the split, the modification is complete, without restarting Tomcat. This article uses this configuration method. The following is a detailed introduction.

(1) Modification of the port

There can be multiple service under the server element, and the port is configured under the service element. The connector element is configured as follows:

<connnector port= "8080" protocal= "http/1.1" connectiontimeout= "20000" redirectport= "8443"/>

Where Protocal developed the protocol type that the port listens on, http/1.1 means listening to the client's HTTP request, that is, we access the port to be entered through the browser, when the port number is 80, you can not enter the port number in the browser address bar, That's why we don't need to specify a port to visit many websites. Sometimes protocal is not specified, the default is http/1.1. Note that this port must be idle.

Under Service, you can configure multiple ports to listen for different protocols.

(2) Virtual host

There must be an engine element under the service element, the engine has a name, and a default virtual hostname, in the following form:

<engine name= "Catalina" defaulthost= "localhost" >

The virtual host is configured under the engine element. The form is as follows:


Unpackwars= "true" autodeploy= "true"

Xmlvalidation= "false" Xmlnamespaceaware= "false" >

</Host>

Name is the name of the virtual host, AppBase is the directory that the virtual host points to, and when Tomcat starts, it automatically loads the app under AppBase. Unpackwars indicates whether an application that has been appbase into a war package is automatically decompressed, Autodeploy indicates whether an application is placed under AppBase and deployed automatically when the server is running.

Tomcat App Deployment

The application can be configured in Server.xml, where the split-up method is described.

The application's standalone profile should be configured under Path $tomcat\conf\enginename\hostname\, where Enginename is the name of the engine where the application resides, and for this example Catalina, Hostname is the name of the virtual host where the application resides, and this example is localhost. The name of the configuration file is such a convention: if the access path is under the virtual host, then the name is empty, such as. xml, in other cases, the file name is the access path, but you need to replace the path with #/. In this example, the access path is/struts, and the corresponding file name is Struts.xml, which reads as follows:

<context docbase= "C:/wap/struts" reloadable= "true"/>

Where docbase specifies the directory where the application is located, if the relative directory, corresponding to the virtual host under the AppBase directory, can also be an absolute directory, this time the application can be anywhere. Reloadable indicates whether a hot deployment is supported, such as a class update, and if Reloadable is true, the app is redeployed. Note: After the split, the Path property of the context will no longer work, which is different from the previous version of Tomcat6.

The above configuration is complete, we can access the application, the access address is http://localhost:8080/struts

The following describes the configuration of resources

The main point here is the configuration of the data source. TOMCAT6 is using the DBCP data source, which is configured as follows:

<resource name= "Jdbc/test" auth= "Application" type= "Javax.sql.DataSource" maxactive= "100"

maxidle= "maxwait=" 10000 "username=" sa "password=" 123456 "Driverclassname=" Com.microsoft.jdbc.sqlserver.SQLServerDriver "

Url= "Jdbc:microsoft:sqlserver://localhost:1433;databasename=test"/>

It can be configured directly under the context element, when the data source is accessible only to the application to which he belongs. If you need all of your applications to be accessible, you can configure them in $tomcat\conf\context.xml directly under the root element. This file will be loaded when you start Tomcat.

If you need to conserve resources and share the same data source, you can configure the Globalnamingresources node in the Server.xml, which can be accessed through aliases in the app, by adding the following child elements under the element where the application resides, for example:

<resoucelink name= "Jdbc/test2" global= "Jdbc/test" type= "Javax.sql.DataSource"/>

Name is the alias, and Global is the resource defined in Globalnamingresources

Tomcat Free Installation Configuration 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.