Are conditions supported in Maven resource filtering?
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
add a comment |
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
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
add a comment |
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
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
java maven velocity
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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>
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
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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>
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
add a comment |
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>
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
add a comment |
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>
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>
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 22 '18 at 8:16
answered Jul 20 '16 at 14:21


Jasper de VriesJasper de Vries
8,90953472
8,90953472
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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