L.Monx
L.Monx

Reputation: 1

Ant load property file and pass value as arg when exec java file

How can I load a value from a property file and pass it as arg when I want to execute a java file?

The content the file of aa.properties: home_path=C:/myhome/apps

The ant:

<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>

Upvotes: 0

Views: 3014

Answers (1)

Rebse
Rebse

Reputation: 10377

you pass it like any other argument to the java task via nested arg values or arg line
Note that vmargs like f.e. -Dwhatever=foobar are passed as jvmarg to the java task

f.e. your propertyfile aa.properties looks like :

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

ant then

<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>

Upvotes: 1

Related Questions