Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SSM projects are frequently deployed as war packages, and tomcat and maven are used to achieve hot deployment configuration

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Background

As we all know, after we finish developing the JavaEE project, we need to deploy the project to the tomcat of the server. A common deployment method is to package the project into a war package and put it under tomcat's webapps, then restart tomcat, and then access it via ip address + port number. There is no problem with this deployment itself, but the problem is that if you need to change and optimize the project frequently in a production environment, you need to frequently package the project into the war package and replace the war package under webapps, which is tedious.

Next, let's talk about how to implement local programming, and then deploy the project to the tomcat of the remote server for hot deployment.

The technology used & tools

Maven (project build and dependency management) tomcat7 plug-in (plug-in deployed to tomcat) tomcat server (web server) compiler recommends IDEA

1. Ensure that the local has permission to use the remote tomcat

Modify the {TOMCAT_HOME} conf/tomcat-users.xml configuration file under Tomcat to add user name, password and permissions.

two。 Configure Tomcat to allow remote access

Create a manager.xml file under the {TOMCAT_HOME} conf/Catalina/localhost/ directory of the remote server and configure the following:

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

Allow= "192.168.0.102"

3. Restart remote Tomcat

Execute it in turn under the bin directory of tomcat

/ / close tomcat./shutdown.sh// and start tomcat./startup.sh

4. Test whether you have permission to use

Access tomcat, such as http://192.168.0.102:8080 (using the ip address of your own server or virtual machine)

Click Manager APP

Enter the account number and password of the tomcat you just configured

If you jump to this page to prove that the configuration is complete

Of course, you can also deploy and replace war on the current page, which is another way of deployment, but it is still not as convenient as hot deployment.

Problem: if a 403 error occurs as follows

403 Access DeniedYou are not authorized to view this page. By default the Manager is only accessible from a browser running on the same machine as Tomcat. If you wish to modify this restriction, you'll need to edit the Manager's context.xml file. If you have already configured the Manager application to allow access and you have used your browsers back button, used a saved book-mark or similar then you may have triggered the cross-site request forgery (CSRF) protection that has been enabled for the HTML interface of the Manager application. You will need to reset this protection by returning to the main Manager page. Once you return to this page, you will be able to continue using the Manager application's HTML interface normally. If you continue to see this access denied message, check that you have the necessary permissions to access this application. If you have not changed any configuration files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp.

Solve

Modify the / webapps/manager/META_INF/context.xml file to comment on the restricted settings for accessed sources in the file

Then just refresh the page without restarting tomcat

5. Configure the administrator account of the remote Tomcat in maven

Add the following under the node in the {MAVEN_HOME} / conf/settings.xml file of the local maven:

Crocutax tomcat tomcat

6. Configure the tomcat7 plug-in for maven in the project

Org.apache.tomcat.maven tomcat7-maven-plugin 2.2 crocutax 8080 http://localhost:8080/manager/text UTF-8 true tomcat tomcat 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 to the project release The default is the tomcat/webapps directory. You can specify a deep-seated directory and leave "/", then deploy the ROOT.war package url under the webapps directory by default: pay attention to 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 to uriEncoding: solve the problem of garbled Chinese parameters 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

7. Start the tomcat deployment command for maven in the project

The "tomcat7:deploy" command can be used for initial deployment (when there is no Root folder under the webapps of tomcat)

If you have deployed to use the * * "tomcat7:redeploy" * * command

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

-DskipTests means to skip the test

Clean tomcat7:redeploy-DskipTests

There is an error that the file can not be found when using it. Just recompile or package it.

You can use IDEA as shown below.

Of course, you can also configure quick startup.

You can also use IDE- > Terminal or the project root directory to open the dos window and enter the maven command

At this point, the hot deployment of tomcat+maven is complete, and there is no need to worry about the tedious packaging and deployment.

Summary

The above is that the SSM projects introduced by the editor are frequently deployed as war packages, and use tomcat and maven to achieve hot deployment configuration. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!

If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report