IDEA development tools maven project by tomcat7 plug remote deployment project

1. Add user tomcat and rights

As it relates to automatically deploy tomcat, so the need to have administrative rights tomcat, while the ordinary tomcat users without administrative privileges, such as through {TOMCAT_HOME}/bin/startup.batafter the start tomcat, in the right side of the Home Manager App , you need to enter an administrator account and password project server can be managed on the project, otherwise we could not manage to enter the page.

Adding users and permissions is also very simple, in the {TOMCAT_HOME}/conf/tomcat-users.xmlfile, </tomcat-users>add the following at the node, create management roles and users, and authorize user management roles:

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

After entering the tomcat Home -> Manager App test administrator account is successfully created

Note:

  • username and password can be customized, used here for simplicity memory tomcat at the same time as the user name and password.
  • Some online blog here configured with a number of privileges, but there did not find their role and significance at this stage.

2. Configure tomcat allow remote access

Tomcat default only allows local deployment, if it is to be deployed to a remote server, you need the remote server, {TOMCAT_HOME}conf/Catalina/localhost/create a directory manager.xmlfile, 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 want to allow some IP have access, you can configure allowthe node, such as

allow="127.0.0.1,192.168.1.*"

Representatives to allow hosts to have access.

Note: If you do not configure this step, the local tomcat server to deploy properly, but the remote tomcat server will be reported under the common problems mentioned Cannot invoke Tomcat manager: Connection reset by peer: socket write errorabnormal

3. Add the administrator account for the maven tomcat

Due to the need to use maven to build and deploy the project, so you need to have administrator maven tomcat's account information.
In the {MAVEN_HOME}/conf/settings.xmlfile <servers>under the node add the following:

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

4. Configure plug tomcat7

Configuring tomcat7 plugin in pom.xml project, meaning specific node or the list below to see comments

<!-- 配置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>tomcat</username> <password>tomcat</password> </configuration> </plugin> 

Node list

  • Server : name and must be {MAVEN_HOME}/conf/settings.xmlconsistent with id server node configuration
  • Port : server port number
  • path : the path to release the project, the default is tomcat / webapps directory, you can specify deep directory, leave '/', the default directory under webapps deployment package ROOT.war
  • url : Note url tomcat7 here and can not modify the suffix must be text, html if it is not a local tomcat deploy, and use localhost ip can be.
  • URIEncoding : Chinese parameters resolve the garbage problem
  • Update : hot deployment, otherwise the latter will error
  • username : Configuring {TOMCAT_HOME}\conf\tomcat-users.xmluser-defined name
  • password : ditto

5. Start tomcat server

By first {TOMCAT_HOME}/bin/startup.batstart after starting tomcat completed and then deploy, otherwise it will be reported as abnormal

Cannot invoke Tomcat manager: Connection refused: connect -> [H
elp 1]

6.maven command to deploy

In IDE-> Terminal project root directory or open dos window, enter the command maven

  • Package Penalty for Clean mvn Tomcat : Deploy (using a plug-in version 1.1, if the configuration of the pom.xml version is 2.2, then the use of such a command error)
  • Package Penalty for Clean mvn tomcat7 : Deploy (using a plug-in version 2.2, they used this)

Then he looked at the rest a command line

...
[INFO] --- maven-war-plugin:2.2:war (default-war) @ cmw ---
[INFO] Packaging webapp
[INFO] Assembling webapp [cmw] in [D:\code\server\chinesemedicine\target\cmw]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\code\server\chinesemedicine\src\main\webapp]
[INFO] Webapp assembled in [887 msecs]
[INFO] Building war: D:\code\server\chinesemedicine\target\cmw.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
[INFO] <<< tomcat7-maven-plugin:2.2:deploy (default-cli) < package @ cmw <<< [INFO] [INFO] [INFO] --- tomcat7-maven-plugin:2.2:deploy (default-cli) @ cmw --- [INFO] Deploying war to http://localhost:8080/cmw Uploading: http://localhost:8080/manager/text/deploy?path=%2Fcmw&update=true Uploaded: http://localhost:8080/manager/text/deploy?path=%2Fcmw&update=true (45960 KB at 40564.5 KB/sec) [INFO] tomcatManager status code:200, ReasonPhrase:OK [INFO] OK - Deployed application at context path /cmw [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 18.075 s [INFO] Finished at: 2017-09-17T11:31:21+08:00 [INFO] Final Memory: 20M/293M [INFO] ------------------------------------------------------------------------ 

Appears BUILD SUCCESS , deployed a success!

Common deployment command in Tomcat7 Plugin Documentation is detailed in a list of several commonly used here:

  • tomcat7: run run the current project
  • tomcat7: deploy deploy the current project
  • tomcat7: redeploy redeployment project
  • tomcat7: undeploy Undeploy the current project

common problem

Tomcat return http status error: 401, Reason Phrase: Unauthorized

Unauthorized access tomcat, tomcat that there is no management authority, if not carried out step 1 of "tomcat add users and permissions" operation, this exception will be reported when remote deployment.

In another case, it has been conf/tomcat-users.xmlconfigured and user permissions

<!-- 创建用户,并授权 -->
<role rolename="manager-gui" /> <role rolename="manager-script" /> <user username="tomcat" password="tomcat" roles="manager-gui, manager-script"/> 

But there are still the exception information, then the test server tomcat Home Manager App, found that tomcat administrator role definition can not be normal landing. This shows the configuration of users and roles a problem, continue troubleshooting, start tomcat log in, we found the following anomalies:

警告: Unexpected exception resolving reference
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 1 字节的 UTF-8 序列的字节 1 无效。 

So there is a suspected cause of influence Chinese characters, delete the comments in Chinese tomcat-users.xml, namely

<!-- 创建用户,并授权 -->

Deploy again, tomcat Manager App test is successful, one-click remote deployment is successful!

Note:

Although this is not the WARN ERROR, but still may cause some of the load of the failed internal procedures leading to loss of function, such as tomcat here started successfully, but the internal configuration management authority has failed, which led to the deployment of remote because there is no permission to fail. So, from the perspective of rigor, if the energy is sufficient, then all WARN can not be ignored.

Connection reset by peer: socket write error

异常信息:[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project cmw: Cannot invoke Tomcat manager: Connection reset by peer: socke
t write error -> [Help 1]

This should be an exception when the deployment most likely to occur, and where the card for a long time. Online search a large circle. The fundamental reason is: when the client makes a request (Request), if not yet fully get a response (response) server connected client and server segments disconnected (e.g., off the net, press the "Stop" button, or the client the browser is closed, etc.), the server will throw this Exception.

This issue needs to troubleshoot in many ways.

1. If the remote server, you need to configure tomcat to allow remote access, see step 2

2. Some said tomcat9 configure user permissions in step 1, the same can not have both a user manager-guiand manager-scriptpermissions, but after I left, still does not solve the problem. Eventually abandon the use of tomcat9, use tomcat7, everything is normal.

3. If the tomcat has deployed the project, we need to redeploy command, that is,mvn tomcat7:redeploy

404 project after deployment

The following three reasons may have resulted in the project after deployment can not access the normal, 404 reported:

  1. If the remote server, make sure that port 8080 has been added to the network rules
  2. pom.xml in tomcat7 plug- pathnode configuration in question
  3. 404 project itself

tomcat memory leak

tomcat logs reported

The web application [/appStore] appears to have started a thread named [Thread-2],but has failed to stop it ,this is very likely to create a memory leak


Non-original, refer to the following Source and
author: Wang Xi Wen
link: https: //www.jianshu.com/p/d4585b83b9dd

Guess you like

Origin www.cnblogs.com/helloworldmybokeyuan/p/11229712.html