Ant,jvmarg,系统属性和引号

Mat*_*teo 14 java ant quotes properties

我们有一个属性,它包含一系列要在Ant脚本中传递给JVM的参数.

示例(请注意第二个条目中的引号):

-Dsql.driver=oracle.jdbc.driver.OracleDriver -Dapp.datasource-properties=URL='jdbc:oracle:thin:@//192.168.56.42:1521/xe':User=user:Password=password  
Run Code Online (Sandbox Code Playgroud)

如果我用echo目标打印变量的内容,我得到预期的结果

<echo message="${jvm.arguments}"/>
Run Code Online (Sandbox Code Playgroud)

产生

-Dsql.driver=oracle.jdbc.driver.OracleDriver -Dapp.datasource-properties=URL='jdbc:oracle:thin:@//192.168.56.42:1521/xe':User=user:Password=password 
Run Code Online (Sandbox Code Playgroud)

然后我将该变量用作JVM的参数.

例:

<junit fork="true" forkmode="once" showoutput="true" printsummary="on">
    <jvmarg
        line="-XX:MaxPermSize=256m -Xms1024M ${jvm.arguments}"
Run Code Online (Sandbox Code Playgroud)

报价被默默地删除.Ant的详细输出给了我

[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'
Run Code Online (Sandbox Code Playgroud)

如何将系统属性传递给包含引号的JVM?(单人还是双人)?

我尝试使用双引号转义它们,但没有效果.

Jay*_*yan 15

我使用<jvmarg>单值

 <jvmarg value="-ea"/>
 <jvmarg value="-Dapp.URL=URL=${jvmargs}"/>
Run Code Online (Sandbox Code Playgroud)

然后用以下行调用...

 ant tests -Djvmargs=\'jdbc:oracle:thin:@//192.168.56.42:1521/xe\':User=user:Password=password -debug
Run Code Online (Sandbox Code Playgroud)

带-debug的输出包含您期望的行.

 [junit] '-ea'
 [junit] '-Dapp.URL=URL='jdbc:oracle:thin:@//192.168.56.42:1521/xe':User=user:Password=password'
Run Code Online (Sandbox Code Playgroud)

line是为了处理与空格分开的参数.它可以进行额外的解析和处理来处理带有空格的输入.我还没检查过代码.