zDev - M2E - WTP OSS
  1. zDev - M2E - WTP OSS
  2. MECLIPSEWTP-119

Web resources filtering with properties-maven-plugin

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 0.12.0
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Global Rank:
      11819

      Description

      Hi!

      I'm using the 0.12.0 version for working with my proyect. I have a master pom.xml with the next plug-in:

      (...)
            <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>properties-maven-plugin</artifactId>
              <version>1.0-alpha-2</version>
              <executions>
                <execution>
                  <phase>validate</phase>
                  <goals>
                    <goal>read-project-properties</goal>
                  </goals>
                  <configuration>
                    <files>
                      <file>${main.basedir}/pom.properties</file>
                    </files>
                  </configuration>
                </execution>
              </executions>
            </plugin>
      (...)
      

      Later, I have a child pom.xml with this kind of filtering:

      (...)
      			<plugin>
         				<groupId>org.apache.maven.plugins</groupId>
         				<artifactId>maven-war-plugin</artifactId>
         				<version>2.1.1</version>
      		   			<configuration>
      			             <webResources>
      			               <resource>
      			                 <filtering>true</filtering>
      			                 <directory>src/main/webapp</directory>
      			               </resource>
      			             </webResources>
      		   			</configuration>
      			</plugin>
      (...)
      

      Inside src/main/webapp I have META-INF/context.xml witch has the next content:

      
      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Proof of filtering: ${project.parent.basedir} -->
      <Context>
              <!-- Specify a JDBC datasource -->
              <Resource name="jdbc/${database.schema.AnfixDb}" auth="Container"
                      type="javax.sql.DataSource" username="${database.anfix.user}" password="${database.anfix.password}"
                      driverClassName="com.mysql.jdbc.Driver"
                      url="${database.url}"
                      maxActive="10" maxIdle="4" />
      
      </Context>
      

      When I deploy the proyect with maven in cli, it works fine. However, When I deploy the project inside Eclipse with m2eclipse, ha has the next content:

      
      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Proof of filtering: /opt/datos/eclipse/anfix-os -->
      <Context>
              <!-- Specify a JDBC datasource -->
              <Resource name="jdbc/${database.schema.AnfixDb}" auth="Container"
                      type="javax.sql.DataSource" username="${database.anfix.user}" password="${database.anfix.password}"
                      driverClassName="com.mysql.jdbc.Driver"
                      url="${database.url}"
                      maxActive="10" maxIdle="4" />
      
      </Context>
      

      As you can see, all properties except one haven't been processed. The property that is well processed is $

      {project.parent.basedir}

      witch is an internal property of Maven. However, my properties haven't been processed. All these properties come from properties-maven-plugin and are readed from $

      {main.basedir}

      /pom.properties.

      As I said, if I do a "mvn package", all work fine and the content of context.xml is the expected. But if I do the deploy with eclipse/m2e, only the properties of Maven works fine.

      Is this a bug or is it a problem with the configuration?

        Activity

        Hide
        Fred Bricon added a comment -

        simply put, properties-maven-plugin is not supported.
        Howver, you can try with

        <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-war-plugin</artifactId>
           <version>2.1.1</version>
           <configuration>
             <filters><filter>${main.basedir}/pom.properties</filter></filters>
             <webResources>
               <resource>
                  <filtering>true</filtering>
                  <directory>src/main/webapp</directory>
               </resource>
            </webResources>
          </configuration
        </plugin>
        

        Moreover, i would recommend limiting resource processing to the files actually needing processing, in order to speed things up (http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html), add something like :

        <includes>
          <include>META-INF/*.xml</include>
        <includes>
        
        Show
        Fred Bricon added a comment - simply put, properties-maven-plugin is not supported. Howver, you can try with <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <filters><filter>${main.basedir}/pom.properties</filter></filters> <webResources> <resource> <filtering>true</filtering> <directory>src/main/webapp</directory> </resource> </webResources> </configuration </plugin> Moreover, i would recommend limiting resource processing to the files actually needing processing, in order to speed things up ( http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html ), add something like : <includes> <include>META-INF/*.xml</include> <includes>
        Hide
        Jorge Pascual added a comment - - edited

        Worked like a charm!! Thank you.

        Yes. I agree with you. I have included only the file that I want to process:

        <plugin>
        	<groupId>org.apache.maven.plugins</groupId>
        	<artifactId>maven-war-plugin</artifactId>
        	<version>2.1.1</version>
        	<configuration>
        		<filters>
        			<filter>../pom.properties</filter>
        		</filters>
        		<webResources>
        			<resource>
        				<filtering>false</filtering>
        				<directory>src/main/webapp</directory>
        				<excludes>
        					<exclude>**/META-INF/*.xml</exclude>
        				</excludes>
        			</resource>
        			<resource>
        				<filtering>true</filtering>
        				<directory>src/main/webapp</directory>
        				<includes>
        					<include>**/META-INF/*.xml</include>
        				</includes>
        			</resource>
        		</webResources>
        	</configuration>
        </plugin>
        

        Thank you so much!

        Show
        Jorge Pascual added a comment - - edited Worked like a charm!! Thank you. Yes. I agree with you. I have included only the file that I want to process: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <filters> <filter>../pom.properties</filter> </filters> <webResources> <resource> <filtering> false </filtering> <directory>src/main/webapp</directory> <excludes> <exclude>**/META-INF/*.xml</exclude> </excludes> </resource> <resource> <filtering> true </filtering> <directory>src/main/webapp</directory> <includes> <include>**/META-INF/*.xml</include> </includes> </resource> </webResources> </configuration> </plugin> Thank you so much!
        Hide
        Jorge Pascual added a comment -

        Sorry Fred. This is a very inestable solution or could it be that am I doing wrong things?

        I have the pom.xml configured as I said in the last comment. However, I do the next sequence in Eclipse:

        a) Import Project
        b) Run As Maven Build...: Goals: package Skip Tests
        It works fine. I see in target/ that I have context.xml parsed.
        c) Run As->Run on Server->Tomcat
        The server do the deployment. However, I see in eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/[application-name]/META-INT/context.xml that isn't parsed.

        How can I force to parse the file before the deployment... that is.. to call the plug-in maven-war-plugin before the deployment.

        My .settings/org.eclipse.wst.common.component is:

        <?xml version="1.0" encoding="UTF-8"?>
        <project-modules id="moduleCoreId" project-version="1.5.0">
            <wb-module deploy-name="app-os-war">
                <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
                <wb-resource deploy-path="/" source-path="/src/main/webapp"/>
                <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
                <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/config"/>
                <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
                <dependent-module archiveName="app-os-jar-1.0-SNAPSHOT-tests.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/app-os-jar/app-os-jar">
                    <dependency-type>uses</dependency-type>
                </dependent-module>
                <property name="context-root" value="app-os-war"/>
                <property name="java-output-path" value="/app-os-war/target/classes"/>
            </wb-module>
        </project-modules>
        

        thank you

        Show
        Jorge Pascual added a comment - Sorry Fred. This is a very inestable solution or could it be that am I doing wrong things? I have the pom.xml configured as I said in the last comment. However, I do the next sequence in Eclipse: a) Import Project b) Run As Maven Build...: Goals: package Skip Tests It works fine. I see in target/ that I have context.xml parsed. c) Run As->Run on Server->Tomcat The server do the deployment. However, I see in eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ [application-name] /META-INT/context.xml that isn't parsed. How can I force to parse the file before the deployment... that is.. to call the plug-in maven-war-plugin before the deployment. My .settings/org.eclipse.wst.common.component is: <?xml version= "1.0" encoding= "UTF-8" ?> <project-modules id= "moduleCoreId" project-version= "1.5.0" > <wb-module deploy-name= "app-os-war" > <wb-resource deploy-path= "/" source-path= "/target/m2e-wtp/web-resources" /> <wb-resource deploy-path= "/" source-path= "/src/main/webapp" /> <wb-resource deploy-path= "/WEB-INF/classes" source-path= "/src/main/java" /> <wb-resource deploy-path= "/WEB-INF/classes" source-path= "/src/main/config" /> <wb-resource deploy-path= "/WEB-INF/classes" source-path= "/src/main/resources" /> <dependent-module archiveName= "app-os-jar-1.0-SNAPSHOT-tests.jar" deploy-path= "/WEB-INF/lib" handle= "module:/resource/app-os-jar/app-os-jar" > <dependency-type>uses</dependency-type> </dependent-module> <property name= "context-root" value= "app-os-war" /> <property name= "java-output-path" value= "/app-os-war/target/classes" /> </wb-module> </project-modules> thank you
        Hide
        Fred Bricon added a comment -

        Jorge,

        could you attach a test project so I can try to reproduce this issue?

        Show
        Fred Bricon added a comment - Jorge, could you attach a test project so I can try to reproduce this issue?
        Hide
        Fred Bricon added a comment -

        Back to the original issue, support for the maven-properties-plugin, this is semi-fixed in m2e 1.0.0 / m2e-wtp 0.13 :

        • m2e will complain the plugin's execution is not covered -> choose quick fix to ignore it
        • it will add a pluginManagement configuration used only by m2e to ignore the plugin. But since you want to execute it, you need to replace <ignore></ignore> by <execute></execute>
        • update you project configuration
        • Now the plugin will execute but fail because it can't find $ {main.basedir}

          . Just remove that placeholder and web filtering will work.

        Allowing the execution of the properties-maven-plugin by default could be added to m2e-core or m2e-extras, so I suggest you open a ticket at https://bugs.eclipse.org/bugs/enter_bug.cgi?product=m2e

        Show
        Fred Bricon added a comment - Back to the original issue, support for the maven-properties-plugin, this is semi-fixed in m2e 1.0.0 / m2e-wtp 0.13 : m2e will complain the plugin's execution is not covered -> choose quick fix to ignore it it will add a pluginManagement configuration used only by m2e to ignore the plugin. But since you want to execute it, you need to replace <ignore></ignore> by <execute></execute> update you project configuration Now the plugin will execute but fail because it can't find $ {main.basedir} . Just remove that placeholder and web filtering will work. Allowing the execution of the properties-maven-plugin by default could be added to m2e-core or m2e-extras, so I suggest you open a ticket at https://bugs.eclipse.org/bugs/enter_bug.cgi?product=m2e

          People

          • Assignee:
            Fred Bricon
            Reporter:
            Jorge Pascual
            Last Updated By:
            Fred Bricon
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Date of First Response: