1. 程式人生 > >tomcat-maven-plugin在pom.xml中的配置

tomcat-maven-plugin在pom.xml中的配置

1、使用tomcat-maven-plugin需要在pom.xml檔案中project>build節點下新增以下程式碼:

 <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat6-maven-plugin</artifactId>
          <version>2.3-SNAPSHOT</version>
        </plugin>
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>2.3-SNAPSHOT</version>
        </plugin>
      </plugins>
    </pluginManagement>
2、新增倉庫資訊,保證maven可以從倉庫中下載到tomcat-maven-plugin外掛

(a)在project>repositories節點下加如下配置資訊

<repository>
	<id>people.apache.snapshots</id>
	<url>
		http://repository.apache.org/content/groups/snapshots-group/
	</url>
	<releases>
		<enabled>false</enabled>
	</releases>
	<snapshots>
		<enabled>true</enabled>
	</snapshots>
</repository>

(b)在project>pluginRepositories下新增如下配置資訊

<pluginRepository>
	<id>apache.snapshots</id>
	<name>Apache Snapshots</name>
	<url>
		http://repository.apache.org/content/groups/snapshots-group/
	</url>
	<releases>
		<enabled>false</enabled>
	</releases>
	<snapshots>
		<enabled>true</enabled>
	</snapshots>
</pluginRepository>

正確的pom.xml檔案為:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>MavenHelloWorld</groupId>
	<artifactId>MavenHelloWorld</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>MavenHelloWorld Maven Webapp</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<repositories>
		<repository>
			<id>people.apache.snapshots</id>
			<url>
			http://repository.apache.org/content/groups/snapshots-group/
		</url>
			<releases>
				<enabled>false</enabled>
			</releases>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>apache.snapshots</id>
			<name>Apache Snapshots</name>
			<url>
			http://repository.apache.org/content/groups/snapshots-group/
		</url>
			<releases>
				<enabled>false</enabled>
			</releases>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>
	<build>
		<finalName>MavenHelloWorld</finalName>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.tomcat.maven</groupId>
					<artifactId>tomcat6-maven-plugin</artifactId>
					<version>2.0-SNAPSHOT</version>
					<configuration>
						<url>http://localhost:8080/manager/text</url>
						<server>tomcat</server>
					</configuration>
				</plugin>
				<plugin>
					<groupId>org.apache.tomcat.maven</groupId>
					<artifactId>tomcat7-maven-plugin</artifactId>
					<version>2.0-SNAPSHOT</version>
					<configuration>
						<url>http://localhost:8080/manager/text</url>
						<server>tomcat</server>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>
</project>