Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant, jvmarg, system properties and quotes

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  

If I print the content of the variable with the echo target I get the expected result

<echo message="${jvm.arguments}"/>

produces

-Dsql.driver=oracle.jdbc.driver.OracleDriver -Dapp.datasource-properties=URL='jdbc:oracle:thin:@//192.168.56.42:1521/xe':User=user:Password=password 

I then use the variable as an argument to the JVM.

Example:

<junit fork="true" forkmode="once" showoutput="true" printsummary="on">
    <jvmarg
        line="-XX:MaxPermSize=256m -Xms1024M ${jvm.arguments}"

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'

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.

like image 681
Matteo Avatar asked Mar 02 '12 11:03

Matteo


1 Answers

I use <jvmarg> with single value

 <jvmarg value="-ea"/>
 <jvmarg value="-Dapp.URL=URL=${jvmargs}"/>

Then this called with following line...

 ant tests -Djvmargs=\'jdbc:oracle:thin:@//192.168.56.42:1521/xe\':User=user:Password=password -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'

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.

like image 166
Jayan Avatar answered Oct 17 '22 04:10

Jayan