Quantcast

how to change the property value at run time

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to change the property value at run time

Irfan.Sayed
Hi All,

 

I need to change the value of a specific property at run time. Can
somebody please let me know how I can do that.

 

Let's say the property name is "JAVA_HOME" and suppose I want to change
the value of that property to "d:\install"

 

Please help.

 

Regards,

Irfan

 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: how to change the property value at run time

Knuplesch, Juergen
Thats just the special thing about ANT-properties: You can not change them, for good reasons.

But JAVA_HOME does not look like an Ant-property. What do you want to do?


--
Jürgen Knuplesch                    www.icongmbh.de
icon Systemhaus GmbH                Tel. +49 711 806098-275
Sophienstraße 40                    
D-70178 Stuttgart                   Fax. +49 711 806098-299

Geschäftsführer: Uwe Seltmann
HRB Stuttgart 17655
USt-IdNr.: DE 811944121
-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]]
Gesendet: Mittwoch, 14. Mai 2008 15:20
An: [hidden email]
Betreff: how to change the property value at run time

Hi All,

 

I need to change the value of a specific property at run time. Can somebody please let me know how I can do that.

 

Let's say the property name is "JAVA_HOME" and suppose I want to change the value of that property to "d:\install"

 

Please help.

 

Regards,

Irfan

 


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: how to change the property value at run time

Lenhof,Danny
You can set java_home at runtime in windows. If you're compiling multiple projects with two version of java it is best not to set java_home as environment variable.

There are multiple ways of achieving the same outcome...here are two ideas.

First, set java_home in a batch file to kick-off the build process and set java home. Create a .bat file and add the following content.
set JAVA_HOME=<to directory path of java>
call ant -f build.xml

Second, create a build.properties in the same directory as build.xml and add the following content.
java.home = <to directory path of java>

Remember to load the properties file in your build.xml i.e. <property file="build.properties"/>

Hope this helps.

-----Original Message-----
From: Knuplesch, Juergen [mailto:[hidden email]]
Sent: Wednesday, May 14, 2008 9:35 AM
To: Ant Users List
Subject: AW: how to change the property value at run time

Thats just the special thing about ANT-properties: You can not change them, for good reasons.

But JAVA_HOME does not look like an Ant-property. What do you want to do?


--
Jürgen Knuplesch                    www.icongmbh.de
icon Systemhaus GmbH                Tel. +49 711 806098-275
Sophienstraße 40                    
D-70178 Stuttgart                   Fax. +49 711 806098-299

Geschäftsführer: Uwe Seltmann
HRB Stuttgart 17655
USt-IdNr.: DE 811944121
-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]]
Gesendet: Mittwoch, 14. Mai 2008 15:20
An: [hidden email]
Betreff: how to change the property value at run time

Hi All,

 

I need to change the value of a specific property at run time. Can somebody please let me know how I can do that.

 

Let's say the property name is "JAVA_HOME" and suppose I want to change the value of that property to "d:\install"

 

Please help.

 

Regards,

Irfan

 


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


This e-mail message, including any attachments, is for the sole use of the person to whom it has been sent, and may contain information that is confidential or legally protected. If you are not the intended recipient or have received this message in error, you are not authorized to copy, distribute, or otherwise use this message or its attachments. Please notify the sender immediately by return e-mail and permanently delete this message and any attachments.  Gartner makes no warranty that this e-mail is error or virus free.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: how to change the property value at run time

Irfan.Sayed
In reply to this post by Knuplesch, Juergen
Thanks a lot. I know that JAVA_HOME is not the ANT - property.
I just wanted to check whether can we change the property value at run time.

Can we have detail list of different properties that ANT supports.??


Regards,
Irfan

-----Original Message-----
From: Knuplesch, Juergen [mailto:[hidden email]]
Sent: Wednesday, May 14, 2008 7:05 PM
To: Ant Users List
Subject: AW: how to change the property value at run time

Thats just the special thing about ANT-properties: You can not change them, for good reasons.

But JAVA_HOME does not look like an Ant-property. What do you want to do?


--
Jürgen Knuplesch                    www.icongmbh.de
icon Systemhaus GmbH                Tel. +49 711 806098-275
Sophienstraße 40                    
D-70178 Stuttgart                   Fax. +49 711 806098-299

Geschäftsführer: Uwe Seltmann
HRB Stuttgart 17655
USt-IdNr.: DE 811944121
-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]]
Gesendet: Mittwoch, 14. Mai 2008 15:20
An: [hidden email]
Betreff: how to change the property value at run time

Hi All,

 

I need to change the value of a specific property at run time. Can somebody please let me know how I can do that.

 

Let's say the property name is "JAVA_HOME" and suppose I want to change the value of that property to "d:\install"

 

Please help.

 

Regards,

Irfan

 


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: how to change the property value at run time

Taj, Abdul
When you say runtime, what do you mean - are you invoking ant from another program? - like a java application.

If yes - you can use the Project class in Ant, refer api and use setProperty method.

If no - then I don't understand what you mean by runtime - just initialize the property in the build xml file.

<property name="" value=""/>

-t


-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
Sent: Wednesday, May 14, 2008 12:07 PM
To: [hidden email]
Subject: RE: how to change the property value at run time

Thanks a lot. I know that JAVA_HOME is not the ANT - property.
I just wanted to check whether can we change the property value at run time.

Can we have detail list of different properties that ANT supports.??


Regards,
Irfan

-----Original Message-----
From: Knuplesch, Juergen [mailto:[hidden email]]
Sent: Wednesday, May 14, 2008 7:05 PM
To: Ant Users List
Subject: AW: how to change the property value at run time

Thats just the special thing about ANT-properties: You can not change them, for good reasons.

But JAVA_HOME does not look like an Ant-property. What do you want to do?


--
Jürgen Knuplesch                    www.icongmbh.de
icon Systemhaus GmbH                Tel. +49 711 806098-275
Sophienstraße 40                    
D-70178 Stuttgart                   Fax. +49 711 806098-299

Geschäftsführer: Uwe Seltmann
HRB Stuttgart 17655
USt-IdNr.: DE 811944121
-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]]
Gesendet: Mittwoch, 14. Mai 2008 15:20
An: [hidden email]
Betreff: how to change the property value at run time

Hi All,

 

I need to change the value of a specific property at run time. Can somebody please let me know how I can do that.

 

Let's say the property name is "JAVA_HOME" and suppose I want to change the value of that property to "d:\install"

 

Please help.

 

Regards,

Irfan

 


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
--------------------------------------------------------

The information contained in this message is intended only for the recipient, and may be a confidential attorney-client communication or may otherwise be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, please be aware that any dissemination or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify us by replying to the message and deleting it from your computer.  The McGraw-Hill Companies, Inc. reserves the right, subject to applicable local law, to monitor and review the content of any electronic message or information sent to or from McGraw-Hill employee e-mail addresses without informing the sender or recipient of the message.
--------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to change the property value at run time

Gilbert Rebhan
In reply to this post by Irfan.Sayed
[hidden email] schrieb:
> Thanks a lot. I know that JAVA_HOME is not the ANT - property.
> I just wanted to check whether can we change the property value at run time.
>
> Can we have detail list of different properties that ANT supports.??

Some stuff that might be helpful to get you started ...


1. the builtin properties

use =

<echoproperties prefix="java"/>
<echoproperties prefix="ant"/>

or

<echoproperties prefix="java" destfile="ant_java.properties"/>
<echoproperties prefix="ant" destfile="ant_default.properties"/>

to see all java / ant's default properties that are automatically set
for any ant script.

2. properties set via -D ...

as with all java apps you can set propertyvalues with -Dpropertyname=value

f.e. in bla.xml you have

<property name="antlogfile" value="/test/logs/ant.log"/>
...
<record name="${antlogfile}" action="start"/>
...
<record name=${antlogfile}" action="stop"/>

when starting ant with
ant -Dantlogfile=/log/ant.log -f mybuild.xml
${antlogfile} holds /log/ant.log
when starting only with
ant -f bla.xml
${antlogfile} holds /test/logs/ant.log

that can be used for defaults

see =
http://ant.apache.org/manual/running.html#commandline

3. the properties set via property /xmlproperty file

you have a file foo.properties with key=value pattern, f.e.
key1=value
key2=anothervalue
...

load the properties in your build.xml

  <property file="foo.properties"/>

<echo>$${key} == ${key1}${line.separator}$${key2} == ${key2}</echo>

btw. $$ is the masking for a $
${line.separator} is one of those builtin java properties, so
the example gets

${key1} == value
${key2} == anothervalue

4. files set via call to ant api by script or special ant tasks

normally ant properties are immutable once set,
but it's possible to overwrite them with the method
project.setProperty("propertyname", "value") called in an ant task
or with <script> task

f.e.

<property name="foo" value="bar"/>

<target name="depends">
    <script language="ruby">
    <![CDATA[
      $project.setProperty "foo", "baz"
    ]]>
    </script>
</target>

<target name="main" depends="depends">
    <echo>
      $${foobar} == ${foobar}
    </echo>
</target>


guess what's the value of foo ...

You'll find special ant tasks that use the same behaviour in

http://antelope.tigris.org/
http://antxtras.sourceforge.net/
http://ant-contrib.sourceforge.net/

But beware, this is against normal ant behaviour !
Only recommended for advanced uses and only when you need to.

there's also a method to set a new property
project.setNewProperty("propertyname", "value")
without overwriting some existing property


4. finally a speciality about filesets

with

<fileset dir="C:/foobar" id="yourID">
  <include name="**/*.xml"/>
</fileset>

the property ${toString:yourID} is automatically set and
holds all files caught by your include pattern in a comma
separated list

you may use that list for further processing, f.e. echoing
to a file, withn <script>, in a task that provides a kind of for loop

in addition = consult the ant manuel and ant user list archives


Regards, Gilbert






---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to change the property value at run time

Vijay Aravamudhan
In reply to this post by Taj, Abdul
I would also look at the documentation about differences between user
defined properties vs the ones defined within the build.xml file.

Another way to change properties at runtime is to read different
property files based on your condition.

hth,
Vijay

Taj, Abdul wrote:

> When you say runtime, what do you mean - are you invoking ant from another program? - like a java application.
>
> If yes - you can use the Project class in Ant, refer api and use setProperty method.
>
> If no - then I don't understand what you mean by runtime - just initialize the property in the build xml file.
>
> <property name="" value=""/>
>
> -t
>
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]
> Sent: Wednesday, May 14, 2008 12:07 PM
> To: [hidden email]
> Subject: RE: how to change the property value at run time
>
> Thanks a lot. I know that JAVA_HOME is not the ANT - property.
> I just wanted to check whether can we change the property value at run time.
>
> Can we have detail list of different properties that ANT supports.??
>
>
> Regards,
> Irfan
>
> -----Original Message-----
> From: Knuplesch, Juergen [mailto:[hidden email]]
> Sent: Wednesday, May 14, 2008 7:05 PM
> To: Ant Users List
> Subject: AW: how to change the property value at run time
>
> Thats just the special thing about ANT-properties: You can not change them, for good reasons.
>
> But JAVA_HOME does not look like an Ant-property. What do you want to do?
>
>
>  

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to change the property value at run time

David Weintraub
In reply to this post by Irfan.Sayed
Once an Ant property is set, you can't change it. However, there are a
few ways to get around this:

1). In an antcall, you set <param> and these parameters are inherited
as properties in the called target:

<target name="first">
    <antcall target="subtask">
        <param name="param1" value="${JAVA_HOME}"/>
    </antcall>
</target>

<target name="second">
    <antcall target="subtask">
       <param name="param1" value="d:/install"/>
    </antcall>
</target>

<target name="default"
     depends="first,second"/>

<target name="subtask">
    <echo message="Param1 is now set to ${param1}"/>
</target>

2). You can do something similar with macrodef

3). Use AntContrib's <var> task:
http://ant-contrib.sourceforge.net/tasks/tasks/variable_task.html.

Running "ant default" will print out two different values for ${param1}.
On Wed, May 14, 2008 at 9:20 AM,  <[hidden email]> wrote:

> Hi All,
>
>
>
> I need to change the value of a specific property at run time. Can
> somebody please let me know how I can do that.
>
>
>
> Let's say the property name is "JAVA_HOME" and suppose I want to change
> the value of that property to "d:\install"
>
>
>
> Please help.
>
>
>
> Regards,
>
> Irfan
>
>
>
>



--
--
David Weintraub
[hidden email]

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: how to change the property value at run time

Irfan.Sayed
Thanks to all. I got the concept now.

Regards,
Irfan

-----Original Message-----
From: David Weintraub [mailto:[hidden email]]
Sent: Thursday, May 15, 2008 7:10 AM
To: Ant Users List
Subject: Re: how to change the property value at run time

Once an Ant property is set, you can't change it. However, there are a
few ways to get around this:

1). In an antcall, you set <param> and these parameters are inherited
as properties in the called target:

<target name="first">
    <antcall target="subtask">
        <param name="param1" value="${JAVA_HOME}"/>
    </antcall>
</target>

<target name="second">
    <antcall target="subtask">
       <param name="param1" value="d:/install"/>
    </antcall>
</target>

<target name="default"
     depends="first,second"/>

<target name="subtask">
    <echo message="Param1 is now set to ${param1}"/>
</target>

2). You can do something similar with macrodef

3). Use AntContrib's <var> task:
http://ant-contrib.sourceforge.net/tasks/tasks/variable_task.html.

Running "ant default" will print out two different values for ${param1}.
On Wed, May 14, 2008 at 9:20 AM,  <[hidden email]> wrote:

> Hi All,
>
>
>
> I need to change the value of a specific property at run time. Can
> somebody please let me know how I can do that.
>
>
>
> Let's say the property name is "JAVA_HOME" and suppose I want to
change

> the value of that property to "d:\install"
>
>
>
> Please help.
>
>
>
> Regards,
>
> Irfan
>
>
>
>



--
--
David Weintraub
[hidden email]

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...