How to configure Tomcat 9.0 in Maven

Keywords: Tomcat Maven xml Apache

The default version of Tomcat used in Maven is 6.0, which is not applicable in many development applications. The commonly used Tomcat plug-ins on the Internet are Tomcat 7-maven-plugin version 2.2,

3.0-r1655215 of tomcat8-maven-plugin (this version needs to be downloaded on the image server, and the specific configuration is as follows)

Add the following configuration to the pom.xml file


<pluginRepositories>
      <pluginRepository>   
        <id>alfresco-public</id>    
        <url>https://artifacts.alfresco.com/nexus/content/groups/public</url>   
      </pluginRepository>    
      <pluginRepository>   
        <id>alfresco-public-snapshots</id>    
        <url>https://artifacts.alfresco.com/nexus/content/groups/public-snapshots</url>    
        <snapshots>   
          <enabled>true</enabled>    
          <updatePolicy>daily</updatePolicy>   
        </snapshots>   
      </pluginRepository>    
      <pluginRepository>   
        <id>beardedgeeks-releases</id>    
        <url>http://beardedgeeks.googlecode.com/svn/repository/releases</url>   
      </pluginRepository>   
</pluginRepositories>

<build>
   <plugins>
       <plugin>
           <groupId>org.apache.tomcat.maven</groupId>
           <artifactId>tomcat8-maven-plugin</artifactId>
           <version>3.0-r1655215</version>
       </plugin>
   </plugins>
</build>  

However, if Tomcat 9.0 is used, there is no corresponding plug-in. To use Tomcat 9.0, the specific configuration is as follows:

1, Find the configuration file tomcat-users.xml (located in the ~Apache Software FoundationTomcat 9.0conf directory) in the installation directory of tomcat, and add the following configuration to the file

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

2. Add the following configuration in the < servers > < servers > tab of Maven's configuration file settings.xml, where the username and password values must be the same as those in tomcat-users.xml

<server>
	<id>tomcat9</id>
	<username>admin</username>
	<password>123</password>
</server>

3. Configure the following in the pom.xml file of the project (the value in the < server > tag here must be consistent with the value in the < ID > tag in the second step of maven configuration, and tomcat9 is set here)

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<version>2.2</version>
				<configuration>
					<!-- Use tomcat9 Deploy app here server Values in tags and step 2 maven In the configuration file id Value consistent-->
					<server>tomcat9</server>
					<update>true</update>
				</configuration>
			</plugin>
		</plugins>
	</build>

After configuration, Tomcat 9 installed locally is available

1. Start the locally installed Tomcat 9.0 server

2. Execute compile command

3. Execute the tomcat7:deploy command to publish the project to tomcat9.0 that has been started

Visit http://localhost:8080/shiroBase

If you need to redeploy, execute the command tomcat7: redeploy

Postscript:

If you can't deploy to tomcat after configuration according to the above method, start the locally installed tomcat server and visit the address of http://localhost:8080, as shown in the following figure

Posted by prinzcy on Sat, 08 Feb 2020 06:10:09 -0800