尝试mvn包时mvn包错误

时间:2014-12-23 01:39:06

标签: java maven

我已经从svn检查了一个项目。我正在尝试使用maven构建项目。

使用mvn compile构建它。

当我尝试命令mvn包时,我收到以下错误。

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.737 s
[INFO] Finished at: 2014-12-22T19:30:54-06:00
[INFO] Final Memory: 12M/155M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war
 (default-war) on project usermanager: Error assembling WAR: webxml attribute is
 required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help
 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE

我发现这是因为,web.xml没有提供给pom.xml。

我已经尝试了堆栈中的答案中给出的所有方法。但似乎没有任何效果

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/maven-v4_0_0.xsd http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.joseph</groupId>
    <artifactId>usermanager</artifactId>
    <packaging>war</packaging>
    <name>User Manager</name>
    <version>1.0</version>
    <description>
        The User Manager is an administration interface for Intranet Users, Groups, Applications, and Permissions.
    </description>
    <url>http://projects.joseph.com/usermanager</url>
    <inceptionYear>2006</inceptionYear>
    <issueManagement>
        <system>Bug Tracker</system>
        <url>http://bugtracker.joseph.com</url>
    </issueManagement>
    <developers>
        <developer>
            <id>lforehand</id>
            <name>Luke Forehand</name>
            <email>lforehand@parts-unltd.com</email>
            <organization>Joseph Corporation</organization>
            <organizationUrl>http://wiki.josephnet.com</organizationUrl>
            <roles>
                <role>Java Developer</role>
            </roles>
        </developer>
    </developers>
    <build>
        <directory>build</directory>
        <testOutputDirectory>build/test-classes</testOutputDirectory>
        <outputDirectory>build/classes</outputDirectory>
        <sourceDirectory>WEB-INF/src</sourceDirectory>
        <testSourceDirectory>test</testSourceDirectory>
        <resources>
            <resource>
                <directory>deploy</directory>
                <includes>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>deploy</directory>
                <includes>
                    <include>**/*.properties</include>
                </includes>
            </testResource>
        </testResources>
    </build>
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.1</version>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jxr-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>changelog-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>taglist-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </reporting>
    <distributionManagement>
        <site>
            <url>scp://josephnet.com/var/www/projects.joseph.com/usermanager</url>
        </site>
        <repository>
            <id>internal</id>
            <name>Joseph Upload Repository</name>
            <url>file:////snap01/Backup/maven-repo</url>
        </repository>
    </distributionManagement>
    <scm>
        <connection>scm:svn:http://toolbox01/usermanager.josephnet.com/</connection>
        <developerConnection>svn://toolbox01/usermanager.josephnet.com/</developerConnection>
        <url>http://toolbox01/usermanager.josephnet.com/</url>
    </scm>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.joseph</groupId>
            <artifactId>joseph-user-common</artifactId>
            <version>1.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>struts</groupId>
            <artifactId>struts</artifactId>
            <version>1.2.9</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.1.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.9</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
            <version>1.3</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>commons-digester</groupId>
            <artifactId>commons-digester</artifactId>
            <version>1.6</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.0.4</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.7.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-dao</artifactId>
            <version>1.2.6</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>1.2.6</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>1.2.6</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>1.2.6</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>1.2.6</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>1.2.6</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</project>

3 个答案:

答案 0 :(得分:3)

默认情况下,此插件需要构建路径中存在WEB-INF / web.xml。如果您没有,请设置以下属性以避免错误

failOnMissingWebXml = false  //case sensitive, default value is true

实施例

<project>
...
 <build>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.5</version>  // Must use 2.1-alpha-2+
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
  </plugin>
 </build>
</project>

创建虚拟web.xml文件不是解决此问题的简洁方法。 apache documentation

中提供了更多配置

答案 1 :(得分:1)

日志已经非常清楚了

我猜您的pom.xml配置如下:

<packaging>war</packaging>

以某种方式打包的War必须有WEB-INF / web.xml文件,您必须在webapp目录中手动添加WEB-INF目录和web.xml文件。

答案 2 :(得分:1)

我遇到了同样的问题并通过修改pom.xml

修复了它
<build>
    <finalName>AngularSpringApp</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
</build>

你可以参考 http://www.javaroots.com/2014/01/webxml-attribute-is-required-error-in.html