我想知道在Maven资源过滤中是否有办法做if
条件。例如。的东西,让我做的事情:Maven资源过滤是否支持条件?
somefile.txt:
...
#if($some.project.property == true)
some text to include here
#endif
...
类似的东西给速度。
我想知道在Maven资源过滤中是否有办法做if
条件。例如。的东西,让我做的事情:Maven资源过滤是否支持条件?
somefile.txt:
...
#if($some.project.property == true)
some text to include here
#endif
...
类似的东西给速度。
简单的回答没有。但是,如果你真的需要条件,你可以看看velocity-maven-plugin,它可以解决你的问题,但它不是要过滤资源,但它的用例可能会起作用。
<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>
谢谢khmarbaise。是的,我也这么认为。 –
仅供参考,在我的例子中,是的资源被正确过滤。我可以替换变量。 –
简单地设置一个属性(每个prole)在某些情况下可能是有用的。
<yourProperty><![CDATA[
<your>
<block>of code</block>
</your>
]]></yourProperty>
如果您不想要代码块,请将该属性设置为空字符串。
我用这个例子来注入一个<data-source>
到我的web.xml
开发构建。
Maven使用Velocity,是的,您应该可以使用该代码,并进行一些语法更改。你试过了吗? –
我试过这个代码,它没有工作。它只输出我的资源文件中的if/else代码而不是解释它。你确定使用速度的maven吗?任何人都可以给我一个例子吗? –
请参阅[此过滤资源](https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-tools/xwiki-commons-tool-license-resources/src/main/resources/META- INF/NOTICE.vm)以及[POM配置](https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-pom/pom.xml#L49-65)。 –