执行 mvn install
时,我收到以下错误:
汇编WAR时出错:需要webxml属性(如果在更新模式下执行,则为预先存在的WEB-INF / web.xml)
我的Web应用程序结构树是这样的:
my-app
|-- pom.xml
|-- src
|-- ...
|-- WebContent
|-- ...
|-- META-INF
|-- WEB-INF
|-- classes
|-- ...
|-- lib
|-- **web.xml**
我的POM文件看起来像这样:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>masters.traffic</groupId>
<artifactId>traffic_web</artifactId>
<packaging>war</packaging>
<name>traffic_web</name>
<version>0.1.0</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
如何正确解决这个问题?
问候
5 回答
我 strongly 建议使用Maven's standard layout:
将Java源代码放在
src/main/java
中(并删除sourceDirectory
元素)将Web应用程序源放在
src/main/webapp
中删除
WEB-INF
下的classes
和lib
目录当然,你可以自定义布局,但这是IMO更多的麻烦和无用的努力而不是好处 . 只需按照惯例 .
我的猜测是
maven-war-plugin
正在寻找src/main/webapp/WEB-INF/web.xml
,但可以't find it, and wants you to specify the (non-maven-standard) location explicitly. If you can' t将WebContent
重命名为webapp
并将其移至src/main/
(推荐)下,你可以尝试将这样的东西添加到你的<build>
看一下这个评论:
Maven: Including a META-INF folder in the classes folder
我相信Maven需要一个名为“webapp”的文件夹,而不是“WebContent” .
我最近遇到了这个问题,问题是我的资源类没有在类的顶部指定初始路径 . 每个方法都指定了一个路径,但没有指定初始路径 .
例:
会工作得很好 . 但,
将不会
如果您正在使用eclispe,请确保右键单击该项目并创建一个Maven“项目” . 您可以使用mvn generate:archetype -B -cpu从命令行编译批处理,但您可能需要手动构建一些内容 . 有了它,它将作为Web应用程序或客户端应用程序运行 . 将此代码添加到pom.xml .