Use tomcat or maven to achieve hot deployment of projects

In the normal project publishing process, we usually use the method to package the project into a war package, place it in the webapps folder of tomcat, and then start the startup.bat file. However, this publishing method is time-consuming and prone to problems.
I checked some information on the Internet, organized and summarized the online information, and organized it into a document after the successful test in person. If you need it, you can continue to read it.
This article is divided into two parts, namely hot deployment and publishing projects on tomcat and configuring hot deployment and publishing in maven of the project.
1. Tomcat hot deployment release project
1. During the development process, if certain operations are required, some configuration files must be changed. The same is true here. Enter the remote desktop through the mstsc command, find the tomcat of the online project, and modify the Tomcat under { TOMCAT_HOME}conf/tomcat-users.xml configuration file, add username, password, and permissions.

<role rolename="manager-gui" />
<role rolename="manager-script" />
<role rolename="admin-gui" />
<role rolename="admin-script" />
<user username="admin" password="123456" roles="manager-gui,manager-script,admin-gui,admin-script"/>

username and password can be configured as required.
2. Configure remote access to tomcat.
Create a manager.xml file in the {TOMCAT_HOME}conf/Catalina/localhost/ directory of the remote server and configure the following:

<?xml version="1.0" encoding="UTF-8"?><Context privileged="true" antiResourceLocking="false" docBase="${catalina.home}/webapps/manager">     <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" /></Context>

If you only want some users to use it, you can configure the IP in allow, for example

allow="192.168.0.102"

Start tomcat. If tomcat is in the startup state, close it first and then restart it. Test whether you have permission to access tomcat, such as http://192.168.0.102:8080 (using your own server or the IP address of the virtual machine)
. After starting tomcat, the familiar tomcat interface will pop up, click the Manager APP in the picture:
insert image description here
After clicking The interface for entering the user name and password will appear, enter the user name and password set in the previously configured username and password, as shown in the figure:
insert image description hereAfter logging in, the following interface will appear:

insert image description here

2. Use maven to achieve quick hot deployment of projects
1. Configure the administrator account of remote Tomcat in
maven Add the following content under the node in the local maven {MAVEN_HOME}/conf/settings.xml file:

<!-- 配置可以操作tomcat的用户名和密码 --><server>  <id>crocutax</id>  <!-- server login name -->  <username>admin</username>  <!-- server login password -->  <password>123456</password></server>

2. Configure maven's tomcat7 plugin in the project

<!-- 配置Tomcat插件 -->
<plugin>
    <groupId>org.apache.tomcat.maven</groupId> 
       <artifactId>tomcat7-maven-plugin</artifactId>
           <version>2.2</version>
                <configuration>
                        <!-- 此处的名字必须和{MAVEN_HOME}/conf/settings.xml中配置的server节点的id一致-->
                                <server>crocutax</server>
                                        <!--服务器端口号-->
                                                <port>8080</port>
                                                        <!-- 项目发布的路径,默认就是tomcat/webapps目录,可以指定深层次目录,        留"/",则默认在webapps目录下部署ROOT.war包-->
                                                                <path></path> 
                                                                       <!-- 注意tomcat7此处的url,不能随意修改,后缀必须是text,不能是html.         如果是本地tomcat部署,用localhost和ip都可以 -->
                                                                               <url>http://localhost:8080/manager/text</url>
                                                                                       <!--<url>http://117.62.110.110:8080/manager/text</url>-->
                                                                                               <!--解决中文参数乱码问题-->
                                                                                                       <uriEncoding>UTF-8</uriEncoding>
                                                                                                               <update>true</update> 
                                                                                                                      <!--配置在tomcat\conf\tomcat-users.xml中定义的用户名--> 
                                                                                                                             <username>admin</username>
                                                                                                                                     <password>123456</password>
                                                                                                                                 </configuration></plugin>

server : the name must be the same as the id of the server node configured in {MAVEN_HOME}/conf/settings.xml
port : server port number
path : the path where the project is published, the default is the tomcat/webapps directory, you can specify a deep directory, leave "/ ", the ROOT.war package url is deployed in the webapps directory by default
: Note that the url here in tomcat7 cannot be modified at will, the suffix must be text, not html. If it is a local tomcat deployment, both localhost and ip can be used uriEncoding: solution Chinese parameter garbled problem
update: hot deployment, otherwise an error will be reported later
username: configure the user name defined in {TOMCAT_HOME}\conf\tomcat-users.xml
password: configure the password defined in {TOMCAT_HOME}\conf\tomcat-users.xml
3. Start maven's tomcat deployment command in the project. For the
initial deployment, you can use the "tomcat7:deploy" command (used when there is no Root folder under tomcat's webapps).
If it has been deployed, use the "tomcat7:redeploy" command.

If you sometimes encounter project conflicts, you can use the command

-DskipTests means skip tests

clean tomcat7:redeploy -DskipTests

When using it, there is an error that the file cannot be found. You can recompile or package it. You can
use IDEA to operate as shown in the figure below.
insert image description here
Of course, you can also configure the shortcut startup and start
insert image description here
insert image description here
insert image description here
it directly after the configuration is completed. Before that, you need to start tomcat first and go to the idea. Start a hot deploy release project.
The above is the operation method of tomcat and maven hot deployment release project, if you have any questions, please leave a message.

Guess you like

Origin blog.csdn.net/fzt12138/article/details/108822044