Maven: include META-INF folder in class folder

I have a very simple WAR project, and I want to include a directory called META-INF at the beginning of the class output folder, where all the compiled Java classes are. I use Maven, but it seems that by default Maven will not include anything that is not a Java class. Therefore, it ignores my META-INF , which is at the top of the src directory. The META-INF contains a file called persistence.xml . Any quick pointers to Maven instructions to put this directory and file in the output folder?

+36
java java-ee web-applications maven-2 maven-plugin
Aug 19 '09 at 2:04
source share
5 answers

In general, for a Maven Java project, files with source files must be located in the src/main/resources subdirectory of the project. The contents of this resources directory are copied to the output directory ( target/classes by default) at the build-process stage.

For Maven WAR projects, this is somewhat more complicated: there is also a src/main/webapp directory in which Maven expects to find WEB-INF/web.xml . To create a WAR file, this file must exist; otherwise, you will see an error message that resembles the following:

 [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) 

Since the WEB-INF must exist under src/main/webapp , I would recommend not defining it again in src/main/resources . Although this is perfectly true and the contents of the two directories will be merged, confusion may occur if the file is defined in both. The contents of src/main/resources will take precedence, as they are copied over the contents from src/main/webapp .

+78
Aug 19 '09 at 8:47
source share
— -

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

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

To specify additional resource directories, see here .

+10
Aug 19 '09 at 2:20
source share

Put this in 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> 
+4
Apr 25 2018-12-12T00:
source share

I will indirectly answer your question by saying that if you had already made the transition to Maven2, I would definitely recommend using Archetype Plugin. Using the webapp archetype ensures that you get a canonical directory structure. Anyone who looks at your source will immediately know where everything is, and there will be no questions as to where your files are going.

+3
Aug 19 '09 at 3:11
source share

Enter the following 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
Apr 13 2018-11-11T00:
source share



All Articles