5

In my Ant skript, i'm executing a program, passing some arguments, of which one is a very long argument:

<exec executable="${conf.GLASSFISH}/bin/asadmin" failonerror="true" vmlauncher="false">
  <arg line="create-auth-realm" />
  <arg line="--classname com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm" />
  <arg line="--property jaas-context=${conf.auth.jaas-context}:datasource-jndi=${conf.auth.datasource-jndi}:user-table=${conf.auth.usertable}:user-name-column=${conf.auth.usernamecolumn}:password-column=${conf.auth.passwordcolumn}:group-table=${conf.auth.grouptable}:group-name-column=${conf.auth.groupnamecolumn}:assign-groups=${conf.auth.assigngroups}:digest-algorithm=${conf.auth.digest}" />
  <arg line="jdbcRealm" />
</exec>

How can i split the 3rd argument into multiple lines, so the ant-skript is more readable (lower line width)? Something like this (\ is just a placeholder to demonstrate what i need):

<exec executable="command">
  <arg line="--property PROP1:\\"/>
  <arg line="PROP2:\\"/>
  <arg line="PROP3\\"/>
</exec>

So when Ant executes this it should result in the following command:

command --property PROP1:PROP2:PROP3

How can i realize that?

Wolkenarchitekt
  • 20,170
  • 29
  • 111
  • 174

2 Answers2

5

arg line is deprecated in Ant. Use arg value instead. See this example from the docs. If you do this, the world will be a happier and safer place.

<target name="help">
  <exec executable="cmd">
    <arg value="/c"/>
    <arg value="ant.bat"/>
    <arg value="-p"/>
  </exec>
</target>  
Chirlo
  • 5,989
  • 1
  • 29
  • 45
Julian Simpson
  • 607
  • 1
  • 5
  • 11
  • 2
    That way, each parameter is seperated from the previous one with a space. I don't want that. All parameters of the executable should be concatenated as ONE string. I still didn't find a possibility to do that. – Wolkenarchitekt Nov 02 '10 at 16:07
  • value will pass even an empty argument to an executable, line will not. This may or may not be desirable. For example, adb '' shell is not understood by the fickle adb tool. Hence the Android build.xml uses line for "${adb.device.arg}". – Stephen Niedzielski Aug 25 '13 at 21:10
  • 1
    How does this answer the question? – fzzfzzfzz Oct 16 '15 at 18:29
  • this is good to know, but it does not help and seems very unrelated to the question => should be a comment instead – Andreas Covidiot Oct 30 '15 at 15:21
  • Not sure if `` was deprecated back in 2010 but it [certainly is not now](https://ant.apache.org/manual/using.html#arg). Maybe you referred to passing command line params to `` which is indeed deprecated in favor of `` with nested `` elements as explained in bold [in the `exec` Parameter docs](https://ant.apache.org/manual/Tasks/exec.html) – Kostas Filios Jul 24 '17 at 15:11
1

You can try this:

  <path id="exec.parms" >
    <pathelement  path="PROP1:" />
    <pathelement  path="PROP2:" />
  </path> 

And then use it in the exec:

<arg pathref="exec.parms" />

You can use the prefix attribute with value "--property " in arg to create the following:

--property PROP1:
--property PROP2:
Eduardo Mauro
  • 1,515
  • 1
  • 26
  • 38
  • 1
    Hmm when i do it that way, Ant appends my home directory to the pathref, resulting in the following argument: /home/mackaz/arg1:/home/mackaz/arg2 but i want an argument like arg1:arg2 – Wolkenarchitekt Nov 02 '10 at 16:12
  • neither `` nor `` work for me here if the line itself is too long to be "digested" :-( (ant 1.9.4): *"[exec] Die Befehlszeile ist zu lang." (command line is too long)* – Andreas Covidiot Oct 30 '15 at 15:28