如何在pom.xml中配置“tomcat7-maven-plugin”?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在pom.xml中配置“tomcat7-maven-plugin”?相关的知识,希望对你有一定的参考价值。

我试图将一个tomcat7-maven-plugin依赖项添加到pom.xml文件并收到错误。我按照tomcat.apache.org的说明进行操作。

cvc-complex-type.2.4.a: Invalid content was found starting with element 'configuration'. One of '{"http://maven.apache.org/POM/4.0.0":type, "http://
 maven.apache.org/POM/4.0.0":classifier, "http://maven.apache.org/POM/4.0.0":scope, "http://maven.apache.org/POM/4.0.0":systemPath, "http://
 maven.apache.org/POM/4.0.0":exclusions, "http://maven.apache.org/POM/4.0.0":optional}' is expected.

我的完整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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.tastyminerals.poems</groupId>
    <artifactId>poemcollection</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <hibernate.version>4.3.5.Final</hibernate.version>
        <mysql.connector.version>5.1.30</mysql.connector.version>
        <spring.version>4.0.3.RELEASE</spring.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.connector.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-jndi</artifactId>
            <version>8.1.14.v20131031</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <url>http://localhost:8080/manager</url>
                <server>localhost</server>
                <path>/${project.build.finalName}</path>
            </configuration>
        </dependency>
    </dependencies>
</project>
答案

应该将Tomcat7-maven-plugin声明为插件,它不是依赖项。您无法将配置标记添加到依赖项,如错误所示。

因此,类似下面的东西应该工作:

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tastyminerals.poems</groupId>
<artifactId>poemcollection</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
            <url>http://localhost:8080/manager</url>
            <server>localhost</server>
            <path>/${project.build.finalName}</path>
        </configuration>
        </plugin>
    </plugins>
</build>
<...>
   </project>
另一答案

我也面临这个问题,当我部署spring web mvc应用程序作为服务器运行时

<!-- https://mvnrepository.com/artifact/org.apache.tomcat.maven/tomcat8-maven-plugin -->

<dependency>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat8-maven-plugin</artifactId>
    <version>3.0-r1756463</version>
</dependency>

这对我有用

以上是关于如何在pom.xml中配置“tomcat7-maven-plugin”?的主要内容,如果未能解决你的问题,请参考以下文章

如何在pom.xml中配置“tomcat7-maven-plugin”?

如何配置 pom.xml 以将 jooq 类生成到两个不同的包中?

java web pom.xml

如何 配置pom.xml去官方仓库下jar包

如何在pom.xml文件中修改build节点

如何配置pom.xml用maven打包java工程