将环境变量传递给 ant 任务,没有 ANT_OPTS [英] Passing environment variable to ant task, without ANT_OPTS
问题描述
我正在调用 Jasper ant 任务,我想设置 org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING
环境变量.我可以将 ANT_OPTS 设置为 -Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false
并且它可以正常工作.但是,我想要一个可以放入 build.xml 的设置,所以我不需要告诉我的队友他们需要设置 ANT_OPTS.
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.
我试过了
<property name="env.org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING"
value="false"/>
但这似乎不起作用.
如何将环境变量传递给 ant 任务?
How can I pass an environment variable to an ant task?
通过不起作用",我的意思是我收到一个错误,说一个属性 用 " 引用,在值中使用时必须转义
如果我通过 ANT_OPTS 进行设置,则不会出现此错误.
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.
推荐答案
使用
任务定义环境前缀:
Use the <property>
task to define an environmental prefix:
<property environment="env"/>
现在,您可以简单地将 env.
添加到您的环境变量中,并将其视为已定义的 Ant 属性:
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 "${env.PATH}""/>
这篇关于将环境变量传递给 ant 任务,没有 ANT_OPTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!