Ant charger le fichier de propriété et transmettre la valeur en tant qu'arg lorsque le fichier java exec


Comment puis-je charger une valeur à partir d'un fichier de propriété et la transmettre en tant qu'arg lorsque je veux exécuter un fichier java?

Le contenu du fichier aa.propriété: home_path=C:/myhome / apps

La fourmi:

<target name="tst">
  <property file="aa.properties"/>
    <property name="homepath" value="${home_path}/"/>
      <java classpathref="clspath" classname="com.mytest.myapp" fork="true">
        <arg value="${homepath}"/>
      </java>
</target>
Author: L.Monx, 2011-07-21

1 answers

Vous le passez comme tout autre argument à la tâche java via des valeurs arg imbriquées ou une ligne arg
Notez que vmargs comme f. e.-Dwhatever=foobar sont passés en tant que jvmarg à la tâche java

F. e. votre propertyfile aa.propriétés ressemble à:

vmarg.foo=-Dsomevalue=whatever
arg.key=value
arg.foo=bar
...

Ant puis

<target name="tst">
 <property file="aa.properties"/>
 <property name="homepath" value="${home_path}/"/>
 <java classpathref="clspath" classname="com.mytest.myapp" fork="true">
  <jvmarg value="${vmarg.foo}"/>
  <arg value="${homepath}"/>
  <arg value="${arg.key}"/>
  <arg value="${arg.foo}"/>
  ...
 </java>
</target>
 1
Author: Rebse, 2011-07-20 20:46:32