9

I am trying to apply maven to an existing project which already has a directory structure in place. All I can find from previous question is the following.

Maven directory structure

However, my requirement is more detailed. Please see below for the directory structure:

 <root dir>
    |
    +--src-java
    |
    +--src-properties
    |
    +--WEB-INF

I know we could have something like

<build>
<sourceDirectory>src-java</sourceDirectory>
...
</build>

But sourceDirectory is for JAVA source code only, if I'm not mistaken.

For the above structure, how do I declare it in pom.xml? Moving the directory is my last option right now.

Community
  • 1
  • 1
Ggg
  • 249
  • 1
  • 7
  • 18

3 Answers3

21

I guess you need to have something similar to below.

Seeing WEB-INF, I assume you want to build a war. Maven war plugin does this. You will need to configure this a bit since the folder structure is non-standard - for instance you may need to specify the location of web.xml using webXml property. These are documented in the usage page.

<build>
    <sourceDirectory>src-java</sourceDirectory>
    ...
    <resources>
      <resource>
        <directory>src-properties</directory>
      </resource>
    </resources>
    ...
    <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warSourceDirectory>WEB-INF</warSourceDirectory>
                    ...
                </configuration>
            </plugin>
     </plugins>
</build>
Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • Yap, I agree. This is the best answer, and suited to my situation. I bet I am not the only one who has the same problem. – Ggg Jan 06 '11 at 03:34
8

You can change the default directory structure declared in the Super POM by overwriting them in your pom.

For your example, e.g.

<sourceDirectory>src-java</sourceDirectory>
<resources>
  <resource>
    <directory>src-properties</directory>
  </resource>
</resources>

Maven will copy all resources to the jar file. If you want to include WEB-INF to the jar it would be best to move it into the specified resource directory. Otherwise you have to copy it by your own (with maven plugins) to the target directory - I suppose.

FrVaBe
  • 47,963
  • 16
  • 124
  • 157
1
 <resources>
  <resource>
    <directory>${project.basedir}/src/main/resources</directory>
  </resource>

From here.

bmargulies
  • 97,814
  • 39
  • 186
  • 310