问题描述
我有一个非常简单的WAR项目,我希望在所有已编译的Java类所在的classes输出文件夹的顶部包含一个名为 META-INF
的目录。
我正在使用Maven,但似乎默认情况下Maven不会包含任何非Java类。所以它忽略了位于 src
目录顶部的 META-INF
目录。
META-INF
目录包含一个名为 persistence.xml
的文件。有关如何指示Maven将此目录和文件放入输出文件夹的快速指示吗?
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?
推荐答案
一般来说,对于Java基于Maven的项目,非源文件应该放在项目的 src / main / resources
子目录中。在 resources 目录的内容被复制到输出目录(默认为 target / classes
) > build-resources 构建阶段。
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.
对于Maven WAR项目,它稍微复杂一些:还有 src / main / webapp
目录,其中Maven希望找到 WEB-INF / web.xml
。要构建WAR文件,该文件必须存在;否则,你会看到如下错误信息:
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:
[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)
因为 WEB-INF
目录必须存在于 src / main / webapp
,我建议避免在 src / main / resources
中再次定义它。虽然这是完全有效的,并且两个目录的内容将被合并,但如果在两者中定义了文件,则会令人困惑。 src / main / resources
的内容优先,因为它们被复制到 src / main / webapp $ c的内容顶部$ c>。
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
.
这篇关于Maven:在classes文件夹中包含META-INF文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!