java 尝试 mvn package 时出现 mvn package 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27612961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mvn package error when trying mvn package
提问by user4215430
I have checked out a project from svn. I am trying to build the project using maven.
我已经从 svn 签出了一个项目。我正在尝试使用 maven 构建项目。
It builds fine with mvn compile.
它使用 mvn compile 构建得很好。
when i try the command mvn package, i get the following error.
当我尝试命令 mvn package 时,出现以下错误。
[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
I find that this is because, the web.xml is not provided to the pom.xml.
我发现这是因为 web.xml 没有提供给 pom.xml。
I have tried all the ways given in the answers in stack over flow. But none does seem to work
我已经尝试了堆栈溢出中答案中给出的所有方法。但似乎没有一个工作
Here is my 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>[email protected]</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>
回答by kamoor
In default this plugin require WEB-INF/web.xml present in build path. If you don'nt have one please set the following property to avoid error
默认情况下,此插件需要 WEB-INF/web.xml 存在于构建路径中。如果您没有,请设置以下属性以避免错误
failOnMissingWebXml = false //case sensitive, default value is true
Example
例子
<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>
Creating dummy web.xml file is not a clean way to fix this issue. More configurations are given in apache documentation
创建虚拟 web.xml 文件不是解决此问题的干净方法。更多配置在apache文档中给出
回答by user1283183
I had the same issue and fixed it by modifiying pom.xml
我遇到了同样的问题并通过修改 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>
You can refer to http://www.javaroots.com/2014/01/webxml-attribute-is-required-error-in.html
可以参考 http://www.javaroots.com/2014/01/webxml-attribute-is-required-error-in.html
回答by LCore
The log has made it very clear
日志已经说得很清楚了
I guess your pom.xml configuration like this:
我猜你的 pom.xml 配置是这样的:
<packaging>war</packaging>
War packaged in a way must have a WEB-INF/web.xml file, you must add the WEB-INF directory and the web.xml file manually in the webapp directory.
以某种方式打包的war必须有WEB-INF/web.xml文件,必须在webapp目录下手动添加WEB-INF目录和web.xml文件。