I have a very simple WAR project and I want to include a directory named META-INF
at the top of the classes output folder where all the compiled Java classes are. I'm using Maven, but it seems that by default Maven won't include anything that is not a Java class. So it ignores my META-INF
directory that is sitting at the top of the src
directory. The META-INF
directory contains a file named persistence.xml
. Any quick pointers on how to instruct Maven to put this directory and file into the output folder?
我有一个非常简单的WAR项目,我想在类输出文件夹的顶部包含一个名为META-INF的目录,其中所有已编译的Java类都是。我正在使用Maven,但似乎默认情况下Maven不会包含任何非Java类。所以它忽略了我位于src目录顶部的META-INF目录。 META-INF目录包含名为persistence.xml的文件。有关如何指示Maven将此目录和文件放入输出文件夹的快速指示?
5 个解决方案
#1
81
In general, for a Java-based Maven project, non-source files should go in the src/main/resources
sub-directory of the project. The contents of that resources
directory are copied to the output directory (by default, target/classes
) during the process-resources phase of the build.
通常,对于基于Java的Maven项目,非源文件应该放在项目的src / main / resources子目录中。在构建的进程资源阶段,该资源目录的内容将复制到输出目录(默认情况下为目标/类)。
For Maven WAR projects, it is slightly more complicated: there is also the src/main/webapp
directory, wherein Maven expects to find WEB-INF/web.xml
. To build your WAR file, that file must exist; otherwise, you'll see an error message like this:
对于Maven WAR项目,它稍微复杂一点:还有src / main / webapp目录,其中Maven希望找到WEB-INF / web.xml。要构建WAR文件,该文件必须存在;否则,您将看到如下错误消息:
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
As the WEB-INF
directory must exist under src/main/webapp
, I'd recommend avoiding defining it again in src/main/resources
. Although this is perfectly valid and the contents of the two directories will be merged, it can get confusing if a file is defined in both. The contents of src/main/resources
will take precedence as they are copied over the top of the contents from src/main/webapp
.
由于WEB-INF目录必须存在于src / main / webapp下,我建议不要在src / main / resources中再次定义它。虽然这是完全有效的,并且两个目录的内容将被合并,但如果在两者中定义了文件,则会令人困惑。 src / main / resources的内容优先,因为它们被复制到src / main / webapp的内容顶部。
#2
#3
4
I'll indirectly answer your question by saying that if you've already made the jump to Maven2 I'd definitely recommend using the Archetype Plugin. Using the webapp archetype will ensure you end up with a canonical directory structure. Anyone else looking at your source will immediiately know where everything is and there won't be any question as to where your files go.
我会间接回答你的问题,如果你已经跳转到Maven2,我肯定会推荐使用Archetype插件。使用webapp原型将确保您最终获得规范的目录结构。任何查看您的来源的人都会立即知道所有内容的位置,并且对于文件的位置不会有任何疑问。
#4
4
Put this into pom.xml:
把它放到pom.xml中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
#5
0
Give the below entry in POM.xml
在POM.xml中给出以下条目
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<!--webappDirectory>/sample/servlet/container/deploy/directory</webappDirectory-->
<packagingExcludes>**/web.xml</packagingExcludes>
</configuration>
</plugin>
#1
81
In general, for a Java-based Maven project, non-source files should go in the src/main/resources
sub-directory of the project. The contents of that resources
directory are copied to the output directory (by default, target/classes
) during the process-resources phase of the build.
通常,对于基于Java的Maven项目,非源文件应该放在项目的src / main / resources子目录中。在构建的进程资源阶段,该资源目录的内容将复制到输出目录(默认情况下为目标/类)。
For Maven WAR projects, it is slightly more complicated: there is also the src/main/webapp
directory, wherein Maven expects to find WEB-INF/web.xml
. To build your WAR file, that file must exist; otherwise, you'll see an error message like this:
对于Maven WAR项目,它稍微复杂一点:还有src / main / webapp目录,其中Maven希望找到WEB-INF / web.xml。要构建WAR文件,该文件必须存在;否则,您将看到如下错误消息:
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
As the WEB-INF
directory must exist under src/main/webapp
, I'd recommend avoiding defining it again in src/main/resources
. Although this is perfectly valid and the contents of the two directories will be merged, it can get confusing if a file is defined in both. The contents of src/main/resources
will take precedence as they are copied over the top of the contents from src/main/webapp
.
由于WEB-INF目录必须存在于src / main / webapp下,我建议不要在src / main / resources中再次定义它。虽然这是完全有效的,并且两个目录的内容将被合并,但如果在两者中定义了文件,则会令人困惑。 src / main / resources的内容优先,因为它们被复制到src / main / webapp的内容顶部。
#2
11
Maven wants this type of information in the resources folder. See here for more information.
Maven希望在资源文件夹中输入此类信息。浏览此处获取更多信息。
Project
|-- pom.xml
`-- src
`-- main
|-- java
`-- resources
For specifying additional resource directories, see here.
要指定其他资源目录,请参见此处。
#3
4
I'll indirectly answer your question by saying that if you've already made the jump to Maven2 I'd definitely recommend using the Archetype Plugin. Using the webapp archetype will ensure you end up with a canonical directory structure. Anyone else looking at your source will immediiately know where everything is and there won't be any question as to where your files go.
我会间接回答你的问题,如果你已经跳转到Maven2,我肯定会推荐使用Archetype插件。使用webapp原型将确保您最终获得规范的目录结构。任何查看您的来源的人都会立即知道所有内容的位置,并且对于文件的位置不会有任何疑问。
#4
4
Put this into pom.xml:
把它放到pom.xml中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
#5
0
Give the below entry in POM.xml
在POM.xml中给出以下条目
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<!--webappDirectory>/sample/servlet/container/deploy/directory</webappDirectory-->
<packagingExcludes>**/web.xml</packagingExcludes>
</configuration>
</plugin>