Are conditions supported in Maven resource filtering?












3















I was wondering if there's a way to do if-conditions in Maven resource filtering. E.g. something that allows me to do:



somefile.txt:



...
#if($some.project.property == true)
some text to include here
#endif
...


Something similar to velocity.










share|improve this question

























  • Maven uses Velocity, and yes, you should be able to use that code, with a few syntax changes. Did you try it?

    – Sergiu Dumitriu
    Jan 4 '13 at 5:18













  • I've tried that code, it didn't work. It only outputs the if/else code in my resource file instead of interpreting it. Are you sure about maven using velocity? Can anyone give me an example?

    – Paul Rivera
    Jan 4 '13 at 6:39











  • See this filtered resource for example, along with the POM configuration.

    – Sergiu Dumitriu
    Jan 4 '13 at 7:20











  • Make sure the file is filtered. Does a simple ${variable} get printed correctly?

    – Sergiu Dumitriu
    Jan 4 '13 at 7:23













  • @SergiuDumitriu Maven uses Velocity for site generation but not for resource filtering.

    – khmarbaise
    Jan 4 '13 at 8:38
















3















I was wondering if there's a way to do if-conditions in Maven resource filtering. E.g. something that allows me to do:



somefile.txt:



...
#if($some.project.property == true)
some text to include here
#endif
...


Something similar to velocity.










share|improve this question

























  • Maven uses Velocity, and yes, you should be able to use that code, with a few syntax changes. Did you try it?

    – Sergiu Dumitriu
    Jan 4 '13 at 5:18













  • I've tried that code, it didn't work. It only outputs the if/else code in my resource file instead of interpreting it. Are you sure about maven using velocity? Can anyone give me an example?

    – Paul Rivera
    Jan 4 '13 at 6:39











  • See this filtered resource for example, along with the POM configuration.

    – Sergiu Dumitriu
    Jan 4 '13 at 7:20











  • Make sure the file is filtered. Does a simple ${variable} get printed correctly?

    – Sergiu Dumitriu
    Jan 4 '13 at 7:23













  • @SergiuDumitriu Maven uses Velocity for site generation but not for resource filtering.

    – khmarbaise
    Jan 4 '13 at 8:38














3












3








3








I was wondering if there's a way to do if-conditions in Maven resource filtering. E.g. something that allows me to do:



somefile.txt:



...
#if($some.project.property == true)
some text to include here
#endif
...


Something similar to velocity.










share|improve this question
















I was wondering if there's a way to do if-conditions in Maven resource filtering. E.g. something that allows me to do:



somefile.txt:



...
#if($some.project.property == true)
some text to include here
#endif
...


Something similar to velocity.







java maven velocity






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 '13 at 5:19









Sergiu Dumitriu

9,50332658




9,50332658










asked Jan 4 '13 at 3:41









Paul RiveraPaul Rivera

284




284













  • Maven uses Velocity, and yes, you should be able to use that code, with a few syntax changes. Did you try it?

    – Sergiu Dumitriu
    Jan 4 '13 at 5:18













  • I've tried that code, it didn't work. It only outputs the if/else code in my resource file instead of interpreting it. Are you sure about maven using velocity? Can anyone give me an example?

    – Paul Rivera
    Jan 4 '13 at 6:39











  • See this filtered resource for example, along with the POM configuration.

    – Sergiu Dumitriu
    Jan 4 '13 at 7:20











  • Make sure the file is filtered. Does a simple ${variable} get printed correctly?

    – Sergiu Dumitriu
    Jan 4 '13 at 7:23













  • @SergiuDumitriu Maven uses Velocity for site generation but not for resource filtering.

    – khmarbaise
    Jan 4 '13 at 8:38



















  • Maven uses Velocity, and yes, you should be able to use that code, with a few syntax changes. Did you try it?

    – Sergiu Dumitriu
    Jan 4 '13 at 5:18













  • I've tried that code, it didn't work. It only outputs the if/else code in my resource file instead of interpreting it. Are you sure about maven using velocity? Can anyone give me an example?

    – Paul Rivera
    Jan 4 '13 at 6:39











  • See this filtered resource for example, along with the POM configuration.

    – Sergiu Dumitriu
    Jan 4 '13 at 7:20











  • Make sure the file is filtered. Does a simple ${variable} get printed correctly?

    – Sergiu Dumitriu
    Jan 4 '13 at 7:23













  • @SergiuDumitriu Maven uses Velocity for site generation but not for resource filtering.

    – khmarbaise
    Jan 4 '13 at 8:38

















Maven uses Velocity, and yes, you should be able to use that code, with a few syntax changes. Did you try it?

– Sergiu Dumitriu
Jan 4 '13 at 5:18







Maven uses Velocity, and yes, you should be able to use that code, with a few syntax changes. Did you try it?

– Sergiu Dumitriu
Jan 4 '13 at 5:18















I've tried that code, it didn't work. It only outputs the if/else code in my resource file instead of interpreting it. Are you sure about maven using velocity? Can anyone give me an example?

– Paul Rivera
Jan 4 '13 at 6:39





I've tried that code, it didn't work. It only outputs the if/else code in my resource file instead of interpreting it. Are you sure about maven using velocity? Can anyone give me an example?

– Paul Rivera
Jan 4 '13 at 6:39













See this filtered resource for example, along with the POM configuration.

– Sergiu Dumitriu
Jan 4 '13 at 7:20





See this filtered resource for example, along with the POM configuration.

– Sergiu Dumitriu
Jan 4 '13 at 7:20













Make sure the file is filtered. Does a simple ${variable} get printed correctly?

– Sergiu Dumitriu
Jan 4 '13 at 7:23







Make sure the file is filtered. Does a simple ${variable} get printed correctly?

– Sergiu Dumitriu
Jan 4 '13 at 7:23















@SergiuDumitriu Maven uses Velocity for site generation but not for resource filtering.

– khmarbaise
Jan 4 '13 at 8:38





@SergiuDumitriu Maven uses Velocity for site generation but not for resource filtering.

– khmarbaise
Jan 4 '13 at 8:38












2 Answers
2






active

oldest

votes


















2














Simple answer no. But if you really need conditions you might take a look into the velocity-maven-plugin which solve your problem but it's not intended to filter resources but your use case it might work.



 <plugin>
<groupId>com.googlecode.velocity-maven-plugin</groupId>
<artifactId>velocity-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<templateFiles>
<directory>/src/main/resources</directory>
<includes>
<include>*.vm</include>
</includes>
</templateFiles>
<templateValues>
<test>foo</test>
</templateValues>
</configuration>
</plugin>





share|improve this answer
























  • Thanks khmarbaise. Yeah, I thought so too.

    – Paul Rivera
    Jan 4 '13 at 9:33











  • FYI, in my example, yes the resource is being filtered correctly. I can have the variables replaced.

    – Paul Rivera
    Jan 4 '13 at 9:33



















1














Simply setting a property (per profile) might be useful in some cases.



<yourProperty><![CDATA[
<your>
<block>of code</block>
</your>
]]></yourProperty>


If you don't want the block of code, set the property to an empty string.



I used this for example to inject a <data-source> into my web.xml for development builds.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14150767%2fare-conditions-supported-in-maven-resource-filtering%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Simple answer no. But if you really need conditions you might take a look into the velocity-maven-plugin which solve your problem but it's not intended to filter resources but your use case it might work.



     <plugin>
    <groupId>com.googlecode.velocity-maven-plugin</groupId>
    <artifactId>velocity-maven-plugin</artifactId>
    <version>1.0.0</version>
    <configuration>
    <templateFiles>
    <directory>/src/main/resources</directory>
    <includes>
    <include>*.vm</include>
    </includes>
    </templateFiles>
    <templateValues>
    <test>foo</test>
    </templateValues>
    </configuration>
    </plugin>





    share|improve this answer
























    • Thanks khmarbaise. Yeah, I thought so too.

      – Paul Rivera
      Jan 4 '13 at 9:33











    • FYI, in my example, yes the resource is being filtered correctly. I can have the variables replaced.

      – Paul Rivera
      Jan 4 '13 at 9:33
















    2














    Simple answer no. But if you really need conditions you might take a look into the velocity-maven-plugin which solve your problem but it's not intended to filter resources but your use case it might work.



     <plugin>
    <groupId>com.googlecode.velocity-maven-plugin</groupId>
    <artifactId>velocity-maven-plugin</artifactId>
    <version>1.0.0</version>
    <configuration>
    <templateFiles>
    <directory>/src/main/resources</directory>
    <includes>
    <include>*.vm</include>
    </includes>
    </templateFiles>
    <templateValues>
    <test>foo</test>
    </templateValues>
    </configuration>
    </plugin>





    share|improve this answer
























    • Thanks khmarbaise. Yeah, I thought so too.

      – Paul Rivera
      Jan 4 '13 at 9:33











    • FYI, in my example, yes the resource is being filtered correctly. I can have the variables replaced.

      – Paul Rivera
      Jan 4 '13 at 9:33














    2












    2








    2







    Simple answer no. But if you really need conditions you might take a look into the velocity-maven-plugin which solve your problem but it's not intended to filter resources but your use case it might work.



     <plugin>
    <groupId>com.googlecode.velocity-maven-plugin</groupId>
    <artifactId>velocity-maven-plugin</artifactId>
    <version>1.0.0</version>
    <configuration>
    <templateFiles>
    <directory>/src/main/resources</directory>
    <includes>
    <include>*.vm</include>
    </includes>
    </templateFiles>
    <templateValues>
    <test>foo</test>
    </templateValues>
    </configuration>
    </plugin>





    share|improve this answer













    Simple answer no. But if you really need conditions you might take a look into the velocity-maven-plugin which solve your problem but it's not intended to filter resources but your use case it might work.



     <plugin>
    <groupId>com.googlecode.velocity-maven-plugin</groupId>
    <artifactId>velocity-maven-plugin</artifactId>
    <version>1.0.0</version>
    <configuration>
    <templateFiles>
    <directory>/src/main/resources</directory>
    <includes>
    <include>*.vm</include>
    </includes>
    </templateFiles>
    <templateValues>
    <test>foo</test>
    </templateValues>
    </configuration>
    </plugin>






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 4 '13 at 8:53









    khmarbaisekhmarbaise

    65.2k18125165




    65.2k18125165













    • Thanks khmarbaise. Yeah, I thought so too.

      – Paul Rivera
      Jan 4 '13 at 9:33











    • FYI, in my example, yes the resource is being filtered correctly. I can have the variables replaced.

      – Paul Rivera
      Jan 4 '13 at 9:33



















    • Thanks khmarbaise. Yeah, I thought so too.

      – Paul Rivera
      Jan 4 '13 at 9:33











    • FYI, in my example, yes the resource is being filtered correctly. I can have the variables replaced.

      – Paul Rivera
      Jan 4 '13 at 9:33

















    Thanks khmarbaise. Yeah, I thought so too.

    – Paul Rivera
    Jan 4 '13 at 9:33





    Thanks khmarbaise. Yeah, I thought so too.

    – Paul Rivera
    Jan 4 '13 at 9:33













    FYI, in my example, yes the resource is being filtered correctly. I can have the variables replaced.

    – Paul Rivera
    Jan 4 '13 at 9:33





    FYI, in my example, yes the resource is being filtered correctly. I can have the variables replaced.

    – Paul Rivera
    Jan 4 '13 at 9:33













    1














    Simply setting a property (per profile) might be useful in some cases.



    <yourProperty><![CDATA[
    <your>
    <block>of code</block>
    </your>
    ]]></yourProperty>


    If you don't want the block of code, set the property to an empty string.



    I used this for example to inject a <data-source> into my web.xml for development builds.






    share|improve this answer






























      1














      Simply setting a property (per profile) might be useful in some cases.



      <yourProperty><![CDATA[
      <your>
      <block>of code</block>
      </your>
      ]]></yourProperty>


      If you don't want the block of code, set the property to an empty string.



      I used this for example to inject a <data-source> into my web.xml for development builds.






      share|improve this answer




























        1












        1








        1







        Simply setting a property (per profile) might be useful in some cases.



        <yourProperty><![CDATA[
        <your>
        <block>of code</block>
        </your>
        ]]></yourProperty>


        If you don't want the block of code, set the property to an empty string.



        I used this for example to inject a <data-source> into my web.xml for development builds.






        share|improve this answer















        Simply setting a property (per profile) might be useful in some cases.



        <yourProperty><![CDATA[
        <your>
        <block>of code</block>
        </your>
        ]]></yourProperty>


        If you don't want the block of code, set the property to an empty string.



        I used this for example to inject a <data-source> into my web.xml for development builds.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 '18 at 8:16

























        answered Jul 20 '16 at 14:21









        Jasper de VriesJasper de Vries

        8,90953472




        8,90953472






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14150767%2fare-conditions-supported-in-maven-resource-filtering%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith