Passing environment variable to ant task, without ANT_OPTS

让人想犯罪 __ 提交于 2019-12-08 00:14:17

问题


I'm calling the Jasper ant task, and I want to set the org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING environment variable. I can set ANT_OPTS to be -Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false and it works correctly. However, I want a setting I can put into the build.xml, so I don't need to tell my teammates that they need to set ANT_OPTS.

I've tried

<property name="env.org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING" 
    value="false"/>

but that doesn't seem to work.

How can I pass an environment variable to an ant task?

EDIT: By "doesn't work", I mean I get an error saying an attribute is quoted with " which must be escaped when used within the value If I set it via ANT_OPTS, I do not get this error.


回答1:


Use the <property> task to define an environmental prefix:

<property environment="env"/>

Now, you can simply prepend env. to your environment variable and treat it like an already defined Ant property:

 <property environment="env"/>
 <echo message="My path is &quot;${env.PATH}&quot;"/>


来源:https://stackoverflow.com/questions/9878326/passing-environment-variable-to-ant-task-without-ant-opts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!