Maven:在类文件夹中包含一个 META-INF 文件夹 [英] Maven: Including a META-INF folder in the classes folder

查看:107
本文介绍了Maven:在类文件夹中包含一个 META-INF 文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的 WAR 项目,我想在所有编译的 Java 类所在的类输出文件夹的顶部包含一个名为 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 子目录中项目目录.在构建的 process-resources 阶段,该 resources 目录的内容被复制到输出目录(默认情况下,target/classes).

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 的内容的顶部.

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:在类文件夹中包含一个 META-INF 文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆