Awesome, I was waiting for an answer. Cheers Avlesh
On Sat, Jul 25, 2009 at 10:23 AM, Jean-Noël Rivasseau <[email protected]>wrote: > I finally found the answer to this; Ant properties set via -D are not the > same as Java properties set via -D when loading Java. When I set the Java > property and not the Ant property, it works. > > Thanks. > > On Fri, Jul 24, 2009 at 5:06 AM, Jean-Noël Rivasseau <[email protected] > >wrote: > > > Thanks for this answer. The problem however is that I don't control the > > code of the Ant task - I am patching the build system of a big package > > (Groovy) to build on Gentoo Linux, so the only thing I can / should > modify > > is the buildfile. Is there a way to tell the Java code that will be run > > inside the task that the current system property "user.home" is set to > "bar" > > ? > > > > Jean-Noel > > > > > > On Thu, Jul 23, 2009 at 8:35 PM, Avlesh Singh <[email protected]> wrote: > > > >> > > >> > 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 < > [email protected] > >> >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 <[email protected]> > >> 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 < > [email protected]> > >> > >>> 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: [email protected] > >> > >>>> For additional commands, e-mail: [email protected] > >> > >>>> > >> > >>>> > >> > >>> > >> > >> 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: [email protected] > >> > > For additional commands, e-mail: [email protected] > >> > > > >> > > >
