Maven:在类文件夹中包含 META-INF 文件夹
我有一个非常简单的 WAR 项目,我想在类输出文件夹的顶部包含一个名为 META-INF
的目录,其中包含所有已编译的 Java 类。 我正在使用 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
一般来说,对于基于Java的Maven项目,非源文件应该放在项目的
src/main/resources
子目录中。在构建的process-resources阶段,该resources
目录的内容被复制到输出目录(默认情况下,target/classes
) 。对于 Maven WAR 项目,情况稍微复杂一些:还有 src/main/webapp 目录,Maven 期望在其中找到 WEB-INF/web.xml 。要构建 WAR 文件,该文件必须存在;否则,您将看到如下错误消息:
由于
WEB-INF
目录必须存在于src/main/webapp
下,我建议避免在中再次定义它src/main/resources
。尽管这是完全有效的并且两个目录的内容将被合并,但如果在两个目录中都定义了文件,则可能会造成混乱。src/main/resources
的内容将优先,因为它们被复制到src/main/webapp
内容的顶部。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 thatresources
directory are copied to the output directory (by default,target/classes
) during the process-resources phase of the build.For Maven WAR projects, it is slightly more complicated: there is also the
src/main/webapp
directory, wherein Maven expects to findWEB-INF/web.xml
. To build your WAR file, that file must exist; otherwise, you'll see an error message like this:As the
WEB-INF
directory must exist undersrc/main/webapp
, I'd recommend avoiding defining it again insrc/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 ofsrc/main/resources
will take precedence as they are copied over the top of the contents fromsrc/main/webapp
.Maven 希望资源文件夹中包含此类信息。请参阅此处了解更多信息。
要指定其他资源目录,请参阅此处。
Maven wants this type of information in the resources folder. See here for more information.
For specifying additional resource directories, see here.
我会间接回答你的问题,如果你已经跳转到 Maven2,我绝对会推荐使用 Archetype 插件。使用 webapp 原型将确保您最终获得规范的目录结构。任何查看您的来源的其他人都会立即知道所有内容在哪里,并且不会有任何关于您的文件去向的问题。
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.
将其放入 pom.xml 中:
Put this into pom.xml:
在 POM.xml 中提供以下条目
Give the below entry in POM.xml