Hot deployment of maven project to remote tomcat

1. Download tomcat from remote server (tomcat depends on jdk, download by Baidu)

  1. First go to the tomcat official website https://tomcat.apache.org/download-80.cgi to view the download path:
    copy the link address on tar.gz under the core in the figure below
    Insert picture description here
  2. Download tomcat
yum install -y wget
wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-8/v8.5.37/bin/apache-tomcat-8.5.37.tar.gz
  1. Unzip and start
tar -zxvf apache-tomcat-8.5.37.tar.gz
./bin/startup.sh
  1. Linux add port opening
参考 https://blog.csdn.net/qq_41622739/article/details/106310418
  1. If you can access the tomcat on the server locally, the configuration is successful.

Two, configure Tomcat Manager user permissions

  1. Tomcat Manager is a Web application that comes with Tomcat and is used to manage Tomcat itself and applications deployed on Tomcat.
    By default, Tomcat Manager is disabled. To be precise, Tomcat Mnager needs to be logged in and authorized as a user role to use the corresponding functions, but Tomcat does not configure any default users, so we need to configure the corresponding user before using the Tomcat Manager.
  2. The Tomcat Manager configuration file path is in the tomcat directory/conf/tomcat-users.xml file.
    By default, the content in the label is commented out. From the comment content, we can see that the user and permissions are configured here, and the comment is There are also clear examples:
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/><user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>

The role label represents the permission rolename represents the permission name.
The user tag represents the user. The username attribute represents the user name, password represents the login password, and role represents the corresponding authority.
Here are the introductions of the four permissions in several tomcat-users:
(1) manager-gui: allows access to the HTML interface, that is, allows the user to access the manager’s html page
(2) manager-script: allows access to pure Text interface, which is to allow script operations on tomcat (maven plug-in requires this permission)
(3) manager-imx: allows access to the JMX proxy interface
(4) manager-status: allows access to the Tomcat read-only status page
. A simple configuration, add the following content in the label, you can access the manager page of tomcat, and at the same time, you can further use maven for remote hot deployment.

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

(The default access link is: localhost:8080/manager) The
following is the manager interface, where you can also operate on the project in tomcat or deploy new projects through the page operation. It's not narrated here.

  1. Modify the tomcat configuration of the remote server according to the above configuration.
  2. Modify the access permissions of the remote tomcat
    Create a manager.xml file in the {TOMCAT_HOME}conf/Catalina/localhost/ directory of the remote server, and configure the following content:
<?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>

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

allow="192.168.0.102"
  1. Test whether you have permission to use
    http://192.168.247.210:8080/manager/html

Three, configure the local maven settings file

  1. Add the following content under the node in the {MAVEN_HOME}/conf/settings.xml file of the local maven:
<!-- 配置可以操作tomcat的用户名和密码 -->
<server>
  <id>demo</id>
  <!-- server login name -->
  <username>tomcat</username>
  <!-- server login password -->
  <password>tomcat</password>
</server>

Fourth, configure the tomcat7 plug-in of maven in the project

  1. Configure Tomcat plugin
<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>tomcat</username>
        <password>tomcat</password>
    </configuration>
</plugin>
配置说明
server : 名字必须和{
    
    MAVEN_HOME}/conf/settings.xml中配置的server节点的id一致
port : 服务器端口号
path :项目发布的路径,默认就是tomcat/webapps目录,可以指定深层次目录,留"/",则默认在webapps目录下部署ROOT.war包
url : 注意tomcat7此处的url,不能随意修改,后缀必须是text,不能是html. 如果是本地tomcat部署,用localhost和ip都可以uriEncoding :解决中文参数乱码问题
update : 热部署,否则后期会报错
username :配置{
    
    TOMCAT_HOME}\conf\tomcat-users.xml中定义的用户名
password :配置{
    
    TOMCAT_HOME}\conf\tomcat-users.xml中定义的密码

Five, idea test

Enter the command on the idea command line:

mvn tomcat7:deploy

Insert picture description here
At this point, the remote deployment is complete.

》》》Bloggers update their learning experience for a long time, recommend likes and follow! ! !
》》》If there is something wrong, please leave a message in the comment area, thank you! ! !

Guess you like

Origin blog.csdn.net/qq_41622739/article/details/108181343