Problems with Tomcat Web application deployment (Multi-Tomcat, specified Java, and bytecode replacement) and tomcat bytecode

Source: Internet
Author: User

Problems with Tomcat Web application deployment (Multi-Tomcat, specified Java, and bytecode replacement) and tomcat bytecode

In this blog post, the operating system environment is CentOS. The goal is to deploy a Tomcat and a Java Web application running on the Tomcat. The deployed system environment is restricted, mainly because Tomcat has been deployed on the host, and the newly deployed Tomcat should not affect the access to the original Tomcat and Corresponding applications. In addition, A certain version of Java has been installed on the system, and environment variables such as JAVA_HOME have been set. The current application depends on another version of Java,
Therefore, the dependency problem must be solved without affecting the configuration of the original application and environment variables.

Tomcat installation

Before installation, prepare the Java environment and configure the JAVA_HOME environment variable (jdk-7u67-linux-x64.rpm ). Next, download the Tomcat program. Here we will use apache-tomcat-7.0.42.tar.gz as an example. You can download it at http://pan.baidu.com/s/1i39wjfz. Download the Tomcat installation file to the/usr/local directory, decompress the file, and rename the directory name as tomcat. Therefore, the Tomcat file is installed under/usr/local/tomcat.
Enter the/usr/local/tomcat/conf directory, write the configuration file server. xml, and modify Tomcat-related configuration information, such as the port number.
Run the following commands in the/usr/local/tomcat/bin directory:

./startup.sh./shutdown.sh

To facilitate the management of tomcat, you can make it a system service and start it as soon as it is started. In this way, you can enable and disable it using the service command. The specific method 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 file content is as follows;
    Use "chmod 777 my_tomcat" to change the File Permission so that it has the executable permission;
  • Then, use "chkconfig-add my_tomcat" to add the system service. After adding the service, you can view it through "chkconfig-list | grep my_tomcat;
  • Use "chkconfig my_tomcat on" to set Automatic startup
#!/bin/bash# chkconfig: - 99 35#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 "$1" in        start)                start                ;;        stop)                stop                ;;        restart)                stop                start                ;;esacexit $RETVAL
Deploy multiple Tomcat servers

First, deploy a new Tomcat Web server on a host without affecting the original Tomcat and applications, that is, deploy multiple Tomcat servers.
As long as the problem of Tomcat port conflict is solved, multiple Tomcat servers can run on the same host. The solution is to configure Tomcat port information, so that no port conflict occurs during Tomcat running. The following default ports are the main ports to be concerned about:
8005 SHUTDOWN Port:
To avoid conflicts, change the port number to port 8006.

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

8080 Access Port
You can change it to another port.

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

8009 AJP Port
Change to port 8010.

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

After modifying the above three types of ports, you can avoid conflicts between multiple Tomcat servers.

Tomcat specifies Java

The preceding section describes how to run multiple Tomcat servers on one host at the same time, while multiple Java servers can be deployed on one host, but only one of the environment variables can be specified. You can also specify a Java for Tomcat, instead of the one specified in JAVA_HOME. The specific method is to modify the setclasspath. sh script in the Tomcat bin directory. Before using JAVA_HOME and JRE_HOME, define these two variables.

export JAVA_HOME=/usr/java/jdk1.7.0_67export JRE_HOME=/usr/java/jdk1.7.0_67/jre
The modified Java Web application replaces the bytecode

After a Java Web application is deployed to Tomcat, some code of the application is sometimes modified. To make the modification take effect, you sometimes need to redeploy the application. However, at this time, it is not necessary to redeploy (delete or replace) all the content. For common JSP files, simply replace the JSP file. For modifications to source programs such as Sevlet and Java that need to be compiled into bytecode, you only need to replace the modified bytecode. The compiled bytecode is located in the classes directory under the WEB-INF directory. Therefore, modify the code and redeploy locally, then find the corresponding. class file under the WEB-INF/classes directory of the local application, replace the corresponding file on the server. Note that the modification takes effect only after tomcat is restarted.

Related Article

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.