Some issues with Tomcat deployment Web application (multiple tomcat, specifying Java, bytecode substitution)

Source: Internet
Author: User
Tags shebang

This blog post operates a system environment for the CentOS system, with the goal of deploying a Tomcat and a Java Web application running on the Tomcat system. The system environment of the deployment is limited, mainly manifested in: Tomcat has been deployed on the host, the newly deployed tomcat should not affect the access of the original Tomcat and the corresponding application, in addition, a version of Java has been installed on the system, set environment variables such as Java_home, And the current application relies on another version of Java,
Therefore, it is necessary to solve the dependency problem on the basis of not affecting the original application and environment variable configuration.

Tomcat installation

Prepare the Java environment before installation and configure the JAVA_HOME environment variable (jdk-7u67-linux-x64.rpm). Then download the Tomcat program, here apache-tomcat-7.0.42.tar.gz as an example, can be downloaded through Http://pan.baidu.com/s/1i39wjfZ. Download the Tomcat installation file to the/usr/local directory and unzip it to rename the directory name to Tomcat, so the Tomcat file is installed under/usr/local/tomcat.
Enter the/usr/local/tomcat/conf directory, write the configuration file Server.xml, and modify the Tomcat-related configuration information, such as the port number.
Then enter the/usr/local/tomcat/bin directory to execute, open and stop the commands are:

./startup.sh./shutdown.sh

To facilitate the management of this tomcat, it can be made into a system service and will be powered on and started, so that it can be turned on and off with the service command. The specific approach is:

    • Create a system service under the/etc/init.d/directory, if the service name is My_tomcat, create the file My_tomcat under/etc/init.d/, the contents of the file are as follows;
      Change file permissions by "chmod 777 My_tomcat" to have executable permissions;
    • The system service is then added via "Chkconfig–add My_tomcat", which can be completed with the "Chkconfig–list | grep my_tomcat "view;
    • Set up boot from "Chkconfig my_tomcat on"
#!/bin/bash# Chkconfig:- about#description: Manage TomcatRetval=0Start(){Echo ' Try to start My Tomcat '    CD/usr/local/tomcat/bin./startup.sh}Stop(){Echo ' Try to stop My Tomcat '    CD/usr/local/tomcat/bin./shutdown.sh}# See how we were called. Case "$" inchStart) Start;        stop) stop;; restart) stop start;;EsacExit $RETVAL
Deploying multiple Tomcat

The first is the deployment of a new Tomcat Web server on a single host, without affecting the original Tomcat and the application, that is, deploying multiple tomcat issues.
As long as the problem of each Tomcat port conflict is resolved, multiple Tomcat can be run on the same host, and the workaround is to configure the port information for Tomcat so that no port conflicts occur during Tomcat operation. The ports you need to focus on are the following default ports:
8005 Shutdown Port:
To avoid the conflict, see the situation changed to Port 8006.

<Server port="8006" shutdown="SHUTDOWN">

8080 Access port
Can be changed to another port

<Connector port="81" protocol="HTTP/1.1"               connectionTimeout="20000"               redirectPort="8443" />

8009 AJP Port
Look, the situation can be changed to Port 8010.

<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />

After modifying the above three categories of ports, you can avoid collisions between multiple tomcat

TOMCAT Specifies Java

The previous section describes how to run multiple tomcat on a single host while multiple Java can be deployed on a single host, only one can be specified in the environment variables. It is also possible to specify a Java specifically for Tomcat, rather than the one specified in Java_home. This is done by modifying the setclasspath.sh script in the Tomcat bin directory and defining both variables before using Java_home and Jre_home.

export JAVA_HOME=/usr/java/jdk1.7.0_67export JRE_HOME=/usr/java/jdk1.7.0_67/jre
Java Web App modified byte code substitution

After a Java web app is deployed to Tomcat, it is sometimes modified to apply some part of the code, and in order for the changes to take effect, it is sometimes necessary to redeploy the app. However, it is not necessary to redeploy all the content (delete, replace), for the normal JSP file is very simple, directly replace the JSP file. For Sevlet, Java and other need to compile into bytecode of the source program modification, you only need to change the compiled code to replace the bytecode can be. The compiled bytecode location is located in the classes directory under the Web-inf directory. Therefore, after you modify the code, redeploy it locally, and then locate the appropriate. class file in the local app's web-inf/classes directory, replacing the corresponding file on the server. Note that you need to restart Tomcat to take effect after the modification.

Some issues with Tomcat deployment Web application (multiple tomcat, specifying Java, bytecode substitution)

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.