Maven:在classes文件夾中包含META-INF文件夾

[英]Maven: Including a META-INF folder in the classes folder


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


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>

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/08/19/729fa965eb3365a6b7ca0700afda31eb.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com