在Maven War插件的单独执行中过滤资源



是否可以过滤资源 - 每个都在单独的执行标签中?我的目标是将2个战争文件和使用不同的过滤器文件过滤的资源进行。实际上,该解决方案不起作用 - 变量没有值,没有触及 <jta-data-source>${ds-jta}</jta-data-source> - 我必须在Maven-War-Plugin之外添加过滤器和资源标签 - 评论部分。我认为可以在执行式围困中指定此"滤波" - 如摘要中所示。

<build>
<!-- I dont want to add this here - I want to have it in execution
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
    <filters>
        <filter>config/1.properties</filter>
    </filters> -->
<plugins>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>3.0.0</version>
      <executions>
         <execution>
            <id>1</id>
            <phase>package</phase>
            <configuration>
               <filters>
                  <filter>config/1.properties</filter>
               </filters>
               <classifier>-1</classifier>
               <webappDirectory>${project.build.directory}/${project.build.finalName}-1</webappDirectory>
               <webResources>
                  <resource>
                     <directory>src/main/resources</directory>
                     <filtering>true</filtering>
                  </resource>
               </webResources>
            </configuration>
            <goals>
               <goal>war</goal>
            </goals>
         </execution>
         <execution>
            <id>2</id>
            <phase>package</phase>
            <configuration>
               <filters>
                  <filter>config/2.properties</filter>
               </filters>
               <classifier>-2</classifier>
               <webappDirectory>${project.build.directory}/${project.build.finalName}-2</webappDirectory>
               <webResources>
                  <resource>
                     <directory>src/main/resources</directory>
                     <filtering>true</filtering>
                  </resource>
               </webResources>
            </configuration>
            <goals>
               <goal>war</goal>
            </goals>
         </execution>
      </executions>
   </plugin>
</plugins>
</build>

有什么线索我缺少什么?

由maven-war-plugin创建的.war看起来像:

  ├── myapp.war
    │   ├── index.html    │   
    │   ├── myapp.properties
    │   ├── logback.xml
    │   ├── META-INF   
    │   │   ├── persistence.xml    
    │   │   
    │   └── WEB-INF          
    │       ├── classes   
    │       │   ├── myapp.properties
    │       │   ├── logback.xml
    │       │   ├── META-INF   
    │       │   │   ├── persistence.xml

我想在persistence.xml中定义的标签<jta-data-source>${ds-server-jta}</jta-data-source>中过滤'ds-server-jta'变量。Maven-War-Plugin仅过滤持久性。XML位于Meta-Inf中。关于以下事实:Maven-war-Plugin用Meta-Infs创建了此.WAR,并且仅过滤了一个持久性。xml(我添加到插件配置):

 <webResources>
     <resource>
         <directory>src/main/resources</directory>
         <filtering>true</filtering>
         <targetPath>WEB-INF/classes</targetPath>
    </resource>
    <resource>
         <directory>src/main/resources</directory>
         <filtering>true</filtering>
    </resource>
 </webResources>

这明确地告诉插件哪些资源要过滤,现在两个文件都按照需要更改。

persistence.xml在我的应用程序服务器(Glassfish)中未使用meta-inf中的persistence.xml,但Maven-War-Plugin无论如何都会创建它。服务器使用的一个是Web-Inf/class/meta-inf/persistence.xml。现在,我试图不创建第一个,而我的.war中的AppServer Meta-Inf目录未使用,但它只是一个小细节。

最新更新