Maven:在类文件夹中包含 META-INF 文件夹

发布于 2024-08-02 04:49:51 字数 292 浏览 2 评论 0原文

我有一个非常简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梦毁影碎の 2024-08-09 04:49:51

一般来说,对于基于Java的Maven项目,非源文件应该放在项目的src/main/resources子目录中。在构建的process-resources阶段,该resources目录的内容被复制到输出目录(默认情况下,target/classes) 。

对于 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)

由于 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 that resources 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 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)

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.

北斗星光 2024-08-09 04:49:51

Maven 希望资源文件夹中包含此类信息。请参阅此处了解更多信息。

Project
|-- pom.xml
`-- src
    `-- main
        |-- java
        `-- resources

要指定其他资源目录,请参阅此处

Maven wants this type of information in the resources folder. See here for more information.

Project
|-- pom.xml
`-- src
    `-- main
        |-- java
        `-- resources

For specifying additional resource directories, see here.

内心荒芜 2024-08-09 04:49:51

我会间接回答你的问题,如果你已经跳转到 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.

哀由 2024-08-09 04:49:51

将其放入 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>

Put this into 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>
说谎友 2024-08-09 04:49:51

在 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>

Give the below entry in 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文