You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jim Garrison <Ji...@troux.com> on 2009/12/09 00:23:55 UTC

ANT Property substutition in log4j.properties

When using

    ANT_ARGS="-lib $LOG4J -Dwork.dir=somepath -listener org.apache.tools.ant.listener.Log4jListener"

where $LOG4J points to a directory containing log4j.jar, with a log4j.properties including:

    log4j.appender.LogFile.file=${work.dir}/build.log

On Windows ${work.dir} in log4j.properties resolves to the value passed in ANT_ARGS, but on Linux it resovles to the empty string, resulting in trying to write the log file into the root, which of course fails. This is using the exact same binaries of ANT and log4j in both environments.
Any ideas what could cause this?


Re: ANT Property substutition in log4j.properties

Posted by David Weintraub <qa...@gmail.com>.
Have you tried exporting the environment variables? Try exporting
ANT_ARGS and see if that works.

In Unix, if you don't export an environment variable, it doesn't get
pushed to the subshell. Windows doesn't have this. In Windows, all
variables are available in each subshell.

Try to create a simple build.xml script, so you can use for experimenting:

<project>
    <property environment="ENV"/>
    <echo>The value of ANT_OPTS is ${ENV.ANT_OPTS}</echo>
    <echo>The value of work.dir is ${work.dir}</echo>
</project>

Then, you can try things like this:

$ ANT_OPTS=-Dwork.dir=barfoo
$ ant
Buildfile: build.xml
     [echo] The value of ANT_OPTS is ${ENV.ANT_OPTS}
     [echo] The value of work.dir is ${work.dir}

BUILD SUCCESSFUL
Total time: 0 seconds
$ export ANT_OPTS
$ ant
Buildfile: build.xml
     [echo] The value of ANT_OPTS is -Dwork.dir=barfoo
     [echo] The value of work.dir is barfoo

BUILD SUCCESSFUL
Total time: 0 seconds

That will allow you to play with various aspects of ant, and see where
the problem could be coming from.

You can also use "set -vx" to help debug your shell scripts. You can
try putting that in /bin/ant (which is a shell script or points to the
shell script that Ant uses. This way, you see each line as it executes
and understand what is happening to the values (for example ANT_OPTS
isn't exported. Therefore, the Ant shell script isn't getting the
value).


On Wed, Dec 9, 2009 at 11:04 AM, Jim Garrison <Ji...@troux.com> wrote:
>> -----Original Message-----
>> From: Antoine Levy Lambert [mailto:antoine@gmx.de]
>> Sent: Wednesday, December 09, 2009 6:43 AM
>> To: Ant Users List
>> Subject: Re: ANT Property substutition in log4j.properties
>>
>> Hello Jim,
>>
>> log4j understands system properties, not ant properties.
>>
>> So most likely these ANT_ARGS on linux do not set a system property
>> but
>> just an ant property. System properties are copied to ant
>> properties,
>> but the reverse is not true.
>>
>> Using ANT_OPTS=-Dwork.dir=somepath should work on both Windows and
>> Linux.
>
> I tried that also, with the same results.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>



-- 
David Weintraub
qazwart@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: ANT Property substutition in log4j.properties

Posted by Jim Garrison <Ji...@troux.com>.
> -----Original Message-----
> From: Antoine Levy Lambert [mailto:antoine@gmx.de]
> Sent: Wednesday, December 09, 2009 6:43 AM
> To: Ant Users List
> Subject: Re: ANT Property substutition in log4j.properties
> 
> Hello Jim,
> 
> log4j understands system properties, not ant properties.
> 
> So most likely these ANT_ARGS on linux do not set a system property
> but
> just an ant property. System properties are copied to ant
> properties,
> but the reverse is not true.
> 
> Using ANT_OPTS=-Dwork.dir=somepath should work on both Windows and
> Linux.

I tried that also, with the same results.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: ANT Property substutition in log4j.properties

Posted by Antoine Levy Lambert <an...@gmx.de>.
Hello Jim,

log4j understands system properties, not ant properties.

So most likely these ANT_ARGS on linux do not set a system property but 
just an ant property. System properties are copied to ant properties, 
but the reverse is not true.

Using ANT_OPTS=-Dwork.dir=somepath should work on both Windows and Linux.

Regards,

Antoine

Jim Garrison wrote:
> When using
>
>     ANT_ARGS="-lib $LOG4J -Dwork.dir=somepath -listener org.apache.tools.ant.listener.Log4jListener"
>
> where $LOG4J points to a directory containing log4j.jar, with a log4j.properties including:
>
>     log4j.appender.LogFile.file=${work.dir}/build.log
>
> On Windows ${work.dir} in log4j.properties resolves to the value passed in ANT_ARGS, but on Linux it resovles to the empty string, resulting in trying to write the log file into the root, which of course fails. This is using the exact same binaries of ANT and log4j in both environments.
> Any ideas what could cause this?
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org