0

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>
1
  • That looks like the correct steps (although you could just use <arg value="${home_path}"/> without the intermediate homepath property). Is something not working? Commented Jul 20, 2011 at 20:48

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Hello I don't know why the 2nd arg is start with "${home_path}" Doesn1t contain the value of home_path
i just used the propertyname ${homepath} from the example of your question
Try echoing the properties to see if they contain what you expect. The syntax you provided should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.