问题描述
尊敬的stackoverflow成员,Maven war插件面临一个奇怪的问题.
Dear stackoverflow members, I am facing a strange issue with Maven war plugin.
我将Eclipse项目的目录结构配置为:
I have comfigurted my eclipse project directory structure as:
Project
|-- pom.xml
-- src
-- main
|-- java
-- resources
-- webapp
|-- WEB-INF
-- web.xml
当我运行maven build命令时,webapp目录中存在的所有文件都将复制到classes文件夹中,这对我来说很奇怪.生成war文件中的结果目录结构为:
When I run the maven build command, all the files present within the webapp directory are copied to the classes folder which is strange to me. The resultant directory structure in the generate war file is:
|-- META-INF
-- WEB-INF
-- classes
--
-- META-INF
-- WEB-INF
我没想到在classes文件夹中有META-INF和WEB-INF文件夹.它正在复制class文件夹不需要的数据,并且这些文件夹已经在war文件的根目录中了.
I didn't expect the META-INF and WEB-INF folders within the classes folder. It's duplicating the data which is not required for the classes folder and these folders are already there at the root of the war file.
请让我知道如何限制Maven War Builder将META-INF和WEB-INF排除在classes文件夹之外?
Please let me know how to restrict the maven war builder to exclude META-INF and WEB-INF going to classes folder ?
推荐答案
我也遇到了这个问题.通过覆盖Maven-war-plugin配置并将其添加到我的pom中,并包括一个< packagingExcludes>
元素来解决该问题:
I had this problem too. It was solved by overriding the maven-war-plugin config by adding it to my pom and including a <packagingExcludes>
element:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>**/webapp</packagingExcludes>
...
</configuration>
</plugin>
</plugin>
像OP一样,这排除了 $ {basedir}/src/main/webapp
内容的复制,包括 META-INF
和 WEB-INF
,到 target/classes/main/webapp
,然后到 target/$ {finalName}/WEB-INF
.
This precluded, as in the OP's case, the copying of the contents of ${basedir}/src/main/webapp
, including META-INF
and WEB-INF
, to target/classes/main/webapp
and subsequently to target/${finalName}/WEB-INF
.
实际上,maven然后按照期望的方式运行,将 $ {basedir}/src/main/webapp
仅 的内容放入 target/$ {finalName}
,然后进入 $ {finalName} .war
In effect, maven then behaved as desired, putting the contents of ${basedir}/src/main/webapp
only into target/${finalName}
and subsequently into the ${finalName}.war
这篇关于Maven War插件将src/main/webapp复制到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!