ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Avlesh Singh <avl...@gmail.com>
Subject Re: How to pass Java system properties to a task defined in a taskdef ?
Date Thu, 23 Jul 2009 18:35:32 GMT
>
> My original question was completely misunderstood
>
Probably because you never mentioned the usage inside a custom task.

Use these within you Ant tasks:
this.getOwningTarget().getProject().getProperty("user.home");
this.getOwningTarget().getProject().getProperties();

Cheers
Avlesh

On Thu, Jul 23, 2009 at 11:55 PM, Jean-Noël Rivasseau <elvanor@gmail.com>wrote:

> Hmm. My original question was completely misunderstood. Here is what I am
> doing:
>
> ant -Duser.home="bar"
>
> The build file looks like this:
>
> <echo message="${user.home}" />
> <taskdef name="mytask" classname="com.example.Test" />
> <mytask />
>
> Then the code in Test.java goes like this:
>
> System.out.println("Property: " + System.getProperty("user.home"));
>
> The result of the Ant echo message is what I expected (eg, it prints out
> bar). However when the mytask task is ran, /home/elvanor is printed out...
> and I need to have the user.home property set for mytask ! Why this happens
> and what can I do about it?
>
> Jean-Noel
>
>
> On Thu, Jul 23, 2009 at 7:34 PM, Scot P. Floess <sfloess@nc.rr.com> wrote:
>
> >
> > You can echo that property using
> >
> > <echo message = "${user.home}"/>
> >
> > Its automagically available via the Java system property...
> >
> >
> > On Thu, 23 Jul 2009, Scot P. Floess wrote:
> >
> >
> >> Well, user.home is a Java system property.  I'm guessing the intent is
> to
> >> change that system property internal to the script?
> >>
> >> On Thu, 23 Jul 2009, Avlesh Singh wrote:
> >>
> >>  If you are trying to read the environment variable "user.home", this is
> >>> how
> >>> you need to it:
> >>>
> >>> <property environment="env"/>
> >>> <echo message = "${env.user.home}"/>
> >>>
> >>> Cheers
> >>> Avlesh
> >>>
> >>> On Thu, Jul 23, 2009 at 8:18 PM, Scot P. Floess <sfloess@nc.rr.com>
> >>> wrote:
> >>>
> >>>
> >>>> Are you trying to set it within your build.xml - like so:
> >>>>
> >>>> <property name="user.home" value="alpha"/>
> >>>>
> >>>> If so, I don't think that is going to work...
> >>>>
> >>>> For example try this out:
> >>>>
> >>>> <project>
> >>>>   <property name="user.home" value="alpha"/>
> >>>>   <echo message = "${user.home}"/>
> >>>> </project>
> >>>>
> >>>> When I run this, I get:
> >>>>
> >>>> Buildfile: build.xml
> >>>>    [echo] /home/sfloess
> >>>>
> >>>> However, if I do this:
> >>>>
> >>>> ant -Duser.home="bar"
> >>>>
> >>>> I get:
> >>>>
> >>>> Buildfile: build.xml
> >>>>    [echo] bar
> >>>>
> >>>> Unless I am wrong, once Ant starts and those default properties are
> set
> >>>> (in
> >>>> this case from Java system properties), it won't be reset to the new
> >>>> value.
> >>>>  However, doing so on the command line sets it first.
> >>>>
> >>>>
> >>>> On Thu, 23 Jul 2009, Scot P. Floess wrote:
> >>>>
> >>>>
> >>>>  Just curious - you mention a modified user.home property...  How are
> >>>>> you
> >>>>> modifying it?
> >>>>>
> >>>>> On Thu, 23 Jul 2009, Jean-Noël Rivasseau wrote:
> >>>>>
> >>>>>  Hello,
> >>>>>
> >>>>>>
> >>>>>> I am launching Ant with a modified user.home property. This
property
> >>>>>> is
> >>>>>> apparently not passed down to one of my tasks, defined in a
taskdef.
> >>>>>> Why?
> >>>>>> Does Ant fork a new VM for executing such tasks? In any case,
how
> can
> >>>>>> I
> >>>>>> pass
> >>>>>> this property to the task being executed, it's essential for
me.
> >>>>>>
> >>>>>> I had a look at the source but could not really understand where
to
> >>>>>> look
> >>>>>> to
> >>>>>> understand how things worked.
> >>>>>>
> >>>>>> Thanks,
> >>>>>>
> >>>>>> Jean-Noel
> >>>>>>
> >>>>>>
> >>>>>>  Scot P. Floess
> >>>>> 27 Lake Royale
> >>>>> Louisburg, NC  27549
> >>>>>
> >>>>> 252-478-8087 (Home)
> >>>>> 919-890-8117 (Work)
> >>>>>
> >>>>> Chief Architect JPlate   http://sourceforge.net/projects/jplate
> >>>>> Chief Architect JavaPIM  http://sourceforge.net/projects/javapim
> >>>>>
> >>>>> Architect Keros          http://sourceforge.net/projects/keros
> >>>>>
> >>>>>
> >>>>>  Scot P. Floess
> >>>> 27 Lake Royale
> >>>> Louisburg, NC  27549
> >>>>
> >>>> 252-478-8087 (Home)
> >>>> 919-890-8117 (Work)
> >>>>
> >>>> Chief Architect JPlate   http://sourceforge.net/projects/jplate
> >>>> Chief Architect JavaPIM  http://sourceforge.net/projects/javapim
> >>>>
> >>>> Architect Keros          http://sourceforge.net/projects/keros
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> >>>> For additional commands, e-mail: user-help@ant.apache.org
> >>>>
> >>>>
> >>>
> >> Scot P. Floess
> >> 27 Lake Royale
> >> Louisburg, NC  27549
> >>
> >> 252-478-8087 (Home)
> >> 919-890-8117 (Work)
> >>
> >> Chief Architect JPlate   http://sourceforge.net/projects/jplate
> >> Chief Architect JavaPIM  http://sourceforge.net/projects/javapim
> >>
> >> Architect Keros          http://sourceforge.net/projects/keros
> >>
> >>
> > Scot P. Floess
> > 27 Lake Royale
> > Louisburg, NC  27549
> >
> > 252-478-8087 (Home)
> > 919-890-8117 (Work)
> >
> > Chief Architect JPlate   http://sourceforge.net/projects/jplate
> > Chief Architect JavaPIM  http://sourceforge.net/projects/javapim
> >
> > Architect Keros          http://sourceforge.net/projects/keros
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message