Use Maven to complete automatic packaging and deploy it to the Linux Server (Tomcat 7), maventomcat7
I recently used maven and tried tomcat deployment by the way. I found a lot of information on the Internet, but it is not the latest. Therefore, I pasted a relatively new Tomcat 7 deployment code and configuration to facilitate future review --> test OK.
1.The first is to configure the tomcat-users.xml under the Tomcat conf directory, configure user permissions, provide to the local Maven use
<role rolename="admin-gui"/><role rolename="admin-script"/><role rolename="manager-gui"/><role rolename="manager-script"/><role rolename="manager-jmx"/><role rolename="manager-status"/><user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
Note: At the beginning, I only configured the manager-gui role. There is no problem locally. I can log on to http: // 127.0.0.1/manager normally, but access http: // 127.0.0.1/manager/text won't work, so if you need to configure it, You can copy it.
After successful login, it indicates that the Tomcat permission has been configured, and the local Maven configuration is followed.
2.My Maven project uses an aggregate project, so I added this plug-in to the parent pom project. I haven't tried Tomcat 6, so I don't know if it works.
<! -- Remote deployment --> <plugin> <groupId> org. apache. tomcat. maven </groupId> <artifactId> tomcat7-maven-plugin </artifactId> <version> 2.2 </version> <configuration> <url> http://xxxxxx.xx.xxx: 8082/manager/text </url> <server> test </server> <username> tomcat </username> <password> tomcat </password> </configuration> </plugin>
Explain that ur l is the Tomcat to which port you want to deploy, not the project directory. Tomcat7 is the default value. If it is 6, text is not required.
3.The configuration of the settings. xml file in Maven is as follows:
<server> <id>test</id> <username>tomcat</username> <password>tomcat</password> </server>
Note: The id corresponds to the server in the pom. xml Maven project. Other usernames and passwords are consistent, that is, the username and password for Tomcat login.
4.If the above configuration is OK, the test is finished. Here I am an aggregation project, so I am going to run the release command in my sub-project. Remember to start Tomcat in advance if you want to release it. Otherwise, an error will be reported.
PS: two obvious problems were encountered in this process: 401 and 403.
401: the username or password is incorrectly configured.
403: There are two situations,
1): the url suffix configured in pom is html, not text. This is a 6 format, 7 is not available, and the suffix can only be text.
<url>http://localhost:8080/manager/html</url>
2): the permissions of tomcat users are incorrectly configured. Configure as follows.
In addition, tomcat must be started first, instead of using IDE To start. Manually run tomcat's startup. bat/sh.
OK.