views:

4271

answers:

3

Hello all,

I have a very simple war project and I want to include a folder:META-INF at the top of the classes output folder where all the compiled java classes are. Im doing this by 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 folder that is sitting at the top of the src folder. The META-INF contains a file persistence.xml. Any quick pointers on how to override this behavior and instruct maven to put this folder and file in the output folder?

+3  A: 

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.

jt
A: 

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.

Zac
+4  A: 

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 the resources directory are copied to the output directory (by default target/classes) in the process-resources phase of the build.

For war projects it is slightly more complicated, there is also the src/main/webapp directory, where Maven expects to find WEB-INF/web.xml. For your war to build that file must exist or 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 direcory 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

Rich Seller
I love you man!
willcodejavaforfood