Подтвердить что ты не робот

Фильтрация файлов Maven в WEB-INF

Я пытаюсь добавить некоторую фильтрацию в файл контекста приложения, который находится в каталоге WEB-INF.

У меня есть файл, который нужно отфильтровать (xmlgateway-context.xml) в папке /src/main/resources.

У меня есть файлы свойств (config-e05.properties) в папке src/main/filters

И у меня POM настроено следующим образом:

<!-- environment profiles -->
<profiles>
 <profile>
  <id>e04</id>
  <properties>
   <targetenv>e04</targetenv>
  </properties>
 </profile>
 <profile>
  <id>e05</id>
  <properties>
   <targetenv>e05</targetenv>
  </properties>
 </profile>
</profiles>

<!-- build settings (filtering) -->
<build>
 <filters>
  <filter>src/main/filters/config-${targetenv}.properties</filter>
 </filters>
 <resources>
  <resource>
   <targetPath>WEB-INF</targetPath>
   <filtering>true</filtering>
   <directory>src/main/resources</directory>
  </resource>
 </resources>
</build>

Это будет корректно установлено mvn, но когда я открою выходной файл войны, я ожидал, что файл xmlgateway-context.xml будет в каталоге /WEB -INF, но он попадает в папку/WEB-INF/классы/WEB-INF.

Как я могу получить этот файл в нужном месте.

В качестве альтернативы, я могу помещать контекст приложения в другое место и ссылаться на него там.

4b9b3361

Ответ 1

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
            <webResources>
                <resource>
                    <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                    <filtering>true</filtering>
                    <targetPath>WEB-INF</targetPath>
                    <includes>
                        <include>**/xmlgateway-context.xml</include>
                     </includes>
                </resource>
            </webResources>
        </configuration>
    </plugin>
</plugins>

Добавьте вышеуказанное значение в свой pom.xml. РЕДАКТИРОВАТЬ: Только для объяснения того, что делает вышеуказанный conf. С этим добавлением mvn собирается фильтровать файлы в src/main/webapp/WEB-INF и, в частности, фильтровать включенные файлы xmlgateway-context.xml, и после фильтрации он будет толкать файлы в папке WEB-INF (это то, что говорит тег target).

Обновить, если что-то неясно.

Ответ 3

С filteringDeploymentDescriptors установлено значение true

     <build>
        <finalName>web-project-name</finalName>
        <filters>
            <filter>src/main/resources/app.properties</filter>
        </filters>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
                </configuration>
            </plugin>           
        </plugins>
    </build>

Ответ 4

Поместите файл xmlgateway-context.xml в src/main/webapp/WEB-INF и настройте следующим образом:

<build>
    <filters>
        <filter>src/main/filters/config-${targetenv}.properties</filter>
    </filters>
    <resources>
        <resource>
                <filtering>true</filtering>
                <directory>src/main/webapp/WEB-INF</directory>
        </resource>
    </resources>
</build>