Maven: Including a META-INF folder in the classes folder

后端 未结 5 1810
长情又很酷
长情又很酷 2020-12-23 11:40

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 ar

相关标签:
5条回答
  • 2020-12-23 12:02

    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.

    0 讨论(0)
  • 2020-12-23 12:03

    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.

    0 讨论(0)
  • 2020-12-23 12:06

    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>
    
    0 讨论(0)
  • 2020-12-23 12:11

    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.

    0 讨论(0)
  • 2020-12-23 12:13

    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>
    
    0 讨论(0)
提交回复
热议问题