In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Using the automatic deployment function of maven, it is very convenient to deploy the maven project to the remote tomcat server, which saves a lot of time.
This article applies to the 7.x, 8.x, 9.x versions of tomcat.
Here are the steps of the automatic department
1. First, configure manager for tomcat
Edit the conf/tomcat-users.xml under the remote tomcat server and add it at the end (in fact, just pull to the end of the file, remove the comments and change it)
Change the above password to your own password, and note that for tomcat9, you cannot give users both the manager-script and manager-gui roles.
Save the tomcat-users.xml.
Create a manager.xml file in the conf/Catalina/localhost/ directory of the tomcat server and write the following values:
Save exit.
Then enter http://serverip:port/manager/html in the browser, and a dialog box asking for a user name and password will pop up, and enter the user and password corresponding to manager-gui to log in to the management console (where serverip is server ip, if the server is local, it is localhost or 127.0.0.1, port is tomcat port, default is 8080). To confirm that the manager is configured correctly. Examples of correct results are as follows:
2, add the configuration to the maven project
In the pom.xml file, add the following plugin node under the plugins node
Org.apache.tomcat.maven tomcat7-maven-plugin 2.2 http://serverip:port/manager/text admin password true / webapp
Replace the serverip and port above with the ip and port of your own tomcat server. Replace the password with the password of the manager-script role configured above. Path changes to the deployment path of the project in the tomcat server.
Then deploy. If it is the first deployment, run mvn tomcat7:deploy to deploy automatically (for tomcat8,9, also use the tomcat7 command). If you update the code and redeploy the update, run mvn tomcat7:redeploy. If the first deployment uses mvn tomcat7:redeploy, only the war file will be uploaded, and the server will not automatically extract the deployment. If the path already exists in the tomcat server and uses the mvn tomcat7:deploy command, true must be configured in the above configuration, otherwise an error will be reported.
If IDE is eclipse, configure a maven build,intellij similar in runas- > run configurations.
3. Memory leak
Serious memory leaks can occur after deployment using the above method. Tomcat's manager provides the ability to diagnose whether memory leaks occur during deployment. At the bottom of the http://serverip:port/manager/html page mentioned above, there is a "Find leaks" button, as follows:
Click the button, and the following message appears in the header of the page indicating that there is a memory leak during deployment:
The above message shows that there is a memory leak in the deployed test project, and if the same project is redeployed multiple times, a project name may appear multiple times.
The reason for memory leaks during deployment is that Tomcat creates a new classloader for the project each time it is redeployed, while the old classloader is not reclaimed by GC. Maven's library classloader-leak-prevention-servlet can be used to solve this problem. The specific plans are as follows:
(1) add maven dependencies:
Se.jiderhamn.classloader-leak-prevention classloader-leak-prevention-servlet 2.1.0
(2) add a Listener to the web.xml of the project (this Listener must be the first Listener in the web.xml, otherwise it will not work)
Se.jiderhamn.classloader.leak.prevention.ClassLoaderLeakPreventorListener
In this way, the memory leak during deployment is resolved.
Note:
1) after adding this Listener, jvm reclaims memory by default 5 seconds after tomcat shuts down. The specific time setting can be found in the third reference link below. Therefore, starting tomcat again within 5 seconds after shutdown may cause problems and lead to invalid startup (consider this problem if the log appears to be normal but the server does not work after tomcat restart).
2) this Listener only solves deployed memory leaks, and memory leaks caused by other problems (such as jdbc, etc.) need to be resolved on their own.
Reference:
Http://stackoverflow.com/questions/7788280/memory-leak-when-redeploying-application-in-tomcat#answer-36295683
Http://java.jiderhamn.se/2011/12/11/classloader-leaks-i-how-to-find-classloader-leaks-with-eclipse-memory-analyser-mat/
Https://github.com/mjiderhamn/classloader-leak-prevention
4, error elimination.
(1) the execution of tomcat7:deploy shows that Build Success is successful but has no effect, and no war package is generated locally. Check whether the packaging tag in the maven configuration file is set to war. That is:
War
If it is not (such as pom), then change it to war.
(2) if there is no problem with the automatic deployment of the local tomcat server, the following Cannot invoke Tomcat manager: Connection reset by peer: socket write error error occurs when deploying to the remote server:
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project webapp: Cannot invoke Tomcat manager: Connection reset by peer: socket write error-> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project clyf_wechat: Cannot invoke Tomcat manager at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java At org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:116) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:80) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51) at org .apache.maven.lifecycle.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:307) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:193) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:106) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:863) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288) at org.apache.maven .cli.MavenCli.main (MavenCli.java:199) at sun.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethod) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:497) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) At org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) Caused by: org.apache.maven.plugin.MojoExecutionException: Cannot invoke Tomcat manager at org.apache.tomcat.maven.plugin.tomcat7.AbstractCatalinaMojo.execute (AbstractCatalinaMojo.java:141) at org.apache.tomcat.maven.plugin.tomcat7.AbstractWarCatalinaMojo.execute (AbstractWarCatalinaMojo.java:68) at org.apache.maven.plugin.DefaultBuildPluginManager. ExecuteMojo (DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:207)... 20 moreCaused by: java.net.SocketException: Connection reset by peer: socket write error at java.net.SocketOutputStream.socketWrite0 (Native Method) at java.net.SocketOutputStream.socketWrite (SocketOutputStream.java:109) at java.net.SocketOutputStream.write (SocketOutputStream.java:153) at org.apache.http.impl.io.AbstractSessionOutputBuffer.write (AbstractSessionOutputBuffer.java:181) at Org.apache.http.impl.io.ContentLengthOutputStream.write (ContentLengthOutputStream.java:115) at org.apache.tomcat.maven.common.deployer.TomcatManager$RequestEntityImplementation.writeTo (TomcatManager.java:880) at org.apache.http.entity.HttpEntityWrapper.writeTo (HttpEntityWrapper.java:89) at org.apache.http.impl.client.EntityEnclosingRequestWrapper$EntityWrapper.writeTo (EntityEnclosingRequestWrapper.java:108) at org.apache.http.impl.entity.EntitySerializer.serialize (EntitySerializer.java:117) at org.apache.http.impl.AbstractHttpClientConnection. SendRequestEntity (AbstractHttpClientConnection.java:265) at org.apache.http.impl.conn.ManagedClientConnectionImpl.sendRequestEntity (ManagedClientConnectionImpl.java:203) at org.apache.http.protocol.HttpRequestExecutor.doSendRequest (HttpRequestExecutor.java:236) at org.apache.http.protocol.HttpRequestExecutor.execute (HttpRequestExecutor.java:121) at org.apache.http.impl.client.DefaultRequestDirector.tryExecute (DefaultRequestDirector.java:682) at org.apache.http.impl.client.DefaultRequestDirector.execute (DefaultRequestDirector.java:486) at org.apache. Http.impl.client.AbstractHttpClient.doExecute (AbstractHttpClient.java:863) at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:82) at org.apache.tomcat.maven.common.deployer.TomcatManager.invoke (TomcatManager.java:742) at org.apache.tomcat.maven.common.deployer.TomcatManager.deployImpl (TomcatManager.java:705) at org.apache.tomcat.maven.common.deployer.TomcatManager.deploy (TomcatManager.java:388) at org.apache.tomcat.maven. Plugin.tomcat7.deploy.AbstractDeployWarMojo.deployWar (AbstractDeployWarMojo.java:85) at org.apache.tomcat.maven.plugin.tomcat7.deploy.AbstractDeployMojo.invokeManager (AbstractDeployMojo.java:82) at org.apache.tomcat.maven.plugin.tomcat7.AbstractCatalinaMojo.execute (AbstractCatalinaMojo.java:132)... 23 more
The following occurs when using mvn tomcat7:redeploy
After querying the Tomcat document, it is found that this is the result of Tomcat's remote address blocker. By default, Manager and Host-Manager of Tomcat only accept local requests. To allow it to accept remote requests, you need to add the manager.xml configuration mentioned above (do not add it after the first step has been configured), that is:
Since Tomcat's Manager can perform sensitive operations such as project deployment and uninstallation, if you only want to allow specific IP addresses to access Manager, you can set the rules in the allow property above. For specific rule settings, see the link below:
Http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Remote_Address_Filter
Problem description: http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Configuring_Manager_Application_Access
(3) automatic deployment shows success, and war package is uploaded successfully, but war does not decompress automatic deployment.
If you deploy a project with the same name by setting a tag in tomcat's server.xml, the war published by maven to the server will not be automatically unzipped, deployed, updated, and need to be untagged from server.xml.
5. Other
If you want to add a version to the deployment path, set the path of the above tomcat7-maven-pluginconfiguration to
/ webapp#version
After deployment, the server-side path of the current project is / webapp/version. For example, if path is set to test#1.0, the actual path of the server project is / test/1.0. As follows:
If there are two # between the name and the version number, the effect is to make the version of the current project displayed in the manager page with the same path. For example, path is set to test##1.0 and the actual deployment path is / test, but in the manager page, it is shown as follows. Note the value in the Version column:
Reference:
Http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.