我想知道在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)。 –