Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using maven using non standard directory layout

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.

like image 656
Ggg Avatar asked Jan 05 '11 11:01

Ggg


People also ask

What is the folder structure of Maven?

maven-project/src/main – contains source code and resources that become part of the artifact. maven-project/src/test – holds all the test code and resources. maven-project/src/it – usually reserved for integration tests used by the Maven Failsafe Plugin.

In which folder artifacts build using Maven are created?

The target folder is the maven default output folder. When a project is build or packaged, all the content of the sources, resources and web files will be put inside of it, it will be used for construct the artifacts and for run tests.


2 Answers

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>
like image 160
Raghuram Avatar answered Nov 16 '22 00:11

Raghuram


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.

like image 33
FrVaBe Avatar answered Nov 16 '22 02:11

FrVaBe