Ant、jvmarg、系统属性和引号 [英] Ant, jvmarg, system properties and quotes
问题描述
我们有一个属性,其中包含要在 Ant 脚本中传递给 JVM 的一系列参数.
We have a property which contains a series of arguments to be passed to the JVM in an Ant script.
示例(注意第二个条目中的引号):
Example (note the quotes in the second entry):
-Dsql.driver=oracle.jdbc.driver.OracleDriver -Dapp.datasource-properties=URL='jdbc:oracle:thin:@//192.168.56.42:1521/xe':User=user:Password=password
如果我用 echo
目标打印变量的内容,我会得到预期的结果
If I print the content of the variable with the echo
target I get the expected result
<echo message="${jvm.arguments}"/>
生产
-Dsql.driver=oracle.jdbc.driver.OracleDriver -Dapp.datasource-properties=URL='jdbc:oracle:thin:@//192.168.56.42:1521/xe':User=user:Password=password
然后我将该变量用作 JVM 的参数.
I then use the variable as an argument to the JVM.
示例:
<junit fork="true" forkmode="once" showoutput="true" printsummary="on">
<jvmarg
line="-XX:MaxPermSize=256m -Xms1024M ${jvm.arguments}"
引号被悄悄删除.Ant的详细输出给了我
The quotes are silently removed. The verbose output of Ant gives me
[junit] Executing '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java' with arguments:
[junit] '-XX:MaxPermSize=256m'
[junit] '-Xms1024M'
[junit] '-Dsql.driver=oracle.jdbc.driver.OracleDriver'
[junit] '-Dapp.datasource-properties=URL=jdbc:oracle:thin:@//192.168.56.42:1521/xe:User=user=password'
如何将包含引号的系统属性传递给 JVM?(单人还是双人)?
How can I pass a system property to the JVM containing quotes? (single or double)?
我尝试转义它们,使用双引号无效.
I tried escaping them, using double quotes with no effect.
推荐答案
I use
with single value
I use <jvmarg>
with single value
<jvmarg value="-ea"/>
<jvmarg value="-Dapp.URL=URL=${jvmargs}"/>
然后调用以下行...
ant tests -Djvmargs=\'jdbc:oracle:thin:@//192.168.56.42:1521/xe\':User=user:Password=password -debug
带有 -debug 的输出包含您期望的行.
The output with -debug has lines expected by you.
[junit] '-ea'
[junit] '-Dapp.URL=URL='jdbc:oracle:thin:@//192.168.56.42:1521/xe':User=user:Password=password'
line
用于处理用空格分隔的参数.它可能会进行额外的解析和处理以处理带有空格的输入.我还没有检查代码.
The line
is meant to process arguments separated with space. It could be doing additional parsing and processing to handle input with whitespace. I have not checked the code yet.
这篇关于Ant、jvmarg、系统属性和引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!