문제

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.

도움이 되었습니까?

해결책

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>

다른 팁

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.

 <resources>
  <resource>
    <directory>${project.basedir}/src/main/resources</directory>
  </resource>

From here.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top