You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Ralph Pöllath <li...@poellath.org> on 2005/04/05 10:49:48 UTC

Filtering properties files

Hi,

I could use some help with filtering properties files.

My project consists of 3 files: project.xml, maven.xml and 
src/conf/log4j.properties (see below).

project.xml defines src/conf as a resource directory with filtering set 
to true.
maven.xml defines a postGoal to war:webapp that copies the 
log4j.properties in place using the ant:copy tag, wrapped in an 
ant:filter tag.
src/conf/log4j.properties contains a token that should be expanded by 
the filter tag.

Something seems to be missing, because running maven war triggers the 
postGoal and does copy the file, but the token isn't expanded. Can 
anyone help?

Thanks,
-Ralph.


$  maven clean war
  __  __
|  \/  |__ _Apache__ ___
| |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
|_|  |_\__,_|\_/\___|_||_|  v. 1.0.2

     ...

war:webapp:
     [echo] Assembling webapp myapp
     ...
     [copy] Copying 1 file to 
/private/tmp/maven-filter/target/myapp/WEB-INF/classes
     [echo] *** executing postGoal of war:webapp
     [copy] Copying 1 file to 
/private/tmp/maven-filter/target/myapp/WEB-INF/classes

war:war:
     [echo] Building WAR myapp
     [jar] Building jar: /private/tmp/maven-filter/target/myapp.war
BUILD SUCCESSFUL
Total time: 5 seconds
Finished at: Tue Apr 05 10:46:00 CEST 2005


// file: project.xml
<?xml version="1.0"?>
<project>
     <pomVersion>3</pomVersion>
     <id>myapp</id>
     <name>myapp</name>
     <build>
         <resources>
             <resource>
                 <filtering>true</filtering>
                 <directory>src/conf</directory>
                 <includes>
                     <include>*.properties</include>
                 </includes>
             </resource>
         </resources>
     </build>
</project>


// file: maven.xml
<project xmlns:maven="jelly:maven" xmlns:ant="jelly:ant">
     <postGoal name="war:webapp">
                 <echo message="*** executing postGoal of war:webapp"/>
                 <ant:filter token="logfile" 
value="/opt/tomcat/logs/myapp.log">
                 <ant:copy overwrite="true" 
file="target/myapp/WEB-INF/classes/log4j.properties" 
tofile="target/myapp/WEB-INF/classes/log4j.properties"/>
                 </ant:filter>
     </postGoal>
</project>


// file: src/conf/log4j.properties
log4j.rootCategory=WARN
# value of next line should be expanded
log4j.appender.logfile.File=@logfile@
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - <%m>%n


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Filtering properties files

Posted by Ralph Pöllath <li...@poellath.org>.
On 05.04.2005, at 11:03, Kenney Westerhof wrote:
> On Tue, 5 Apr 2005, [ISO-8859-1] Ralph Pöllath wrote:
>
> Short answer: add   filtering="true" to ant:copy.
>
> Long answer:
>
> You can define a preGoal to java:jar-resources and define the
> filter there ( <filter token="..." value="..."/> ).

Thanks Kenney. The short answer didn't help, but the long one did.

The key point seems to be that the copying is performed by 
java:jar-resources, so adding the filter to a goal that's executed 
later in the chain will obviously not work. I was mislead by the 
following:

war:webapp:
     [echo] Assembling webapp myapp
    ...
     [copy] Copying 1 file to 
/private/tmp/maven-filter/target/myapp/WEB-INF/classes

For the archives, here's my working maven.xml:

// file: maven.xml
<project xmlns:maven="jelly:maven" xmlns:ant="jelly:ant">
     <preGoal name="java:jar-resources">
     		<ant:filter token="logfile" value="/opt/tomcat/logs/myapp.log"/>
     </preGoal>
</project>

> Resources defined in project.xml get included in the artifact, so you
> don't need to copy it to the WEB-INF/classes directory.

I know. That was a desperate attempt to trigger an additional filtering 
copy, beacuse the built-in filter didn't work for me.

Cheers,
-Ralph.

>> Hi,
>>
>> I could use some help with filtering properties files.
>>
>> My project consists of 3 files: project.xml, maven.xml and
>> src/conf/log4j.properties (see below).
>>
>> project.xml defines src/conf as a resource directory with filtering 
>> set
>> to true.
>> maven.xml defines a postGoal to war:webapp that copies the
>> log4j.properties in place using the ant:copy tag, wrapped in an
>> ant:filter tag.
>> src/conf/log4j.properties contains a token that should be expanded by
>> the filter tag.
>>
>> Something seems to be missing, because running maven war triggers the
>> postGoal and does copy the file, but the token isn't expanded. Can
>> anyone help?
>>
>> Thanks,
>> -Ralph.
>>
>>
>> $  maven clean war
>>   __  __
>> |  \/  |__ _Apache__ ___
>> | |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
>> |_|  |_\__,_|\_/\___|_||_|  v. 1.0.2
>>
>>      ...
>>
>> war:webapp:
>>      [echo] Assembling webapp myapp
>>      ...
>>      [copy] Copying 1 file to
>> /private/tmp/maven-filter/target/myapp/WEB-INF/classes
>>      [echo] *** executing postGoal of war:webapp
>>      [copy] Copying 1 file to
>> /private/tmp/maven-filter/target/myapp/WEB-INF/classes
>>
>> war:war:
>>      [echo] Building WAR myapp
>>      [jar] Building jar: /private/tmp/maven-filter/target/myapp.war
>> BUILD SUCCESSFUL
>> Total time: 5 seconds
>> Finished at: Tue Apr 05 10:46:00 CEST 2005
>>
>>
>> // file: project.xml
>> <?xml version="1.0"?>
>> <project>
>>      <pomVersion>3</pomVersion>
>>      <id>myapp</id>
>>      <name>myapp</name>
>>      <build>
>>          <resources>
>>              <resource>
>>                  <filtering>true</filtering>
>>                  <directory>src/conf</directory>
>>                  <includes>
>>                      <include>*.properties</include>
>>                  </includes>
>>              </resource>
>>          </resources>
>>      </build>
>> </project>
>>
>>
>> // file: maven.xml
>> <project xmlns:maven="jelly:maven" xmlns:ant="jelly:ant">
>>      <postGoal name="war:webapp">
>>                  <echo message="*** executing postGoal of 
>> war:webapp"/>
>>                  <ant:filter token="logfile"
>> value="/opt/tomcat/logs/myapp.log">
>>                  <ant:copy overwrite="true"
>> file="target/myapp/WEB-INF/classes/log4j.properties"
>> tofile="target/myapp/WEB-INF/classes/log4j.properties"/>
>>                  </ant:filter>
>>      </postGoal>
>> </project>
>>
>>
>> // file: src/conf/log4j.properties
>> log4j.rootCategory=WARN
>> # value of next line should be expanded
>> log4j.appender.logfile.File=@logfile@
>> log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
>> log4j.appender.logfile.DatePattern='.'yyyy-MM-dd'.log'
>> log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
>> log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - <%m>%n


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Filtering properties files

Posted by Kenney Westerhof <fo...@neonics.com>.
On Tue, 5 Apr 2005, [ISO-8859-1] Ralph P�llath wrote:

Short answer: add   filtering="true" to ant:copy.

Long answer:

You can define a preGoal to java:jar-resources and define the
filter there ( <filter token="..." value="..."/> ).
Resources defined in project.xml get included in the artifact, so you
don't need to copy it to the WEB-INF/classes directory.


> Hi,
>
> I could use some help with filtering properties files.
>
> My project consists of 3 files: project.xml, maven.xml and
> src/conf/log4j.properties (see below).
>
> project.xml defines src/conf as a resource directory with filtering set
> to true.
> maven.xml defines a postGoal to war:webapp that copies the
> log4j.properties in place using the ant:copy tag, wrapped in an
> ant:filter tag.
> src/conf/log4j.properties contains a token that should be expanded by
> the filter tag.
>
> Something seems to be missing, because running maven war triggers the
> postGoal and does copy the file, but the token isn't expanded. Can
> anyone help?
>
> Thanks,
> -Ralph.
>
>
> $  maven clean war
>   __  __
> |  \/  |__ _Apache__ ___
> | |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
> |_|  |_\__,_|\_/\___|_||_|  v. 1.0.2
>
>      ...
>
> war:webapp:
>      [echo] Assembling webapp myapp
>      ...
>      [copy] Copying 1 file to
> /private/tmp/maven-filter/target/myapp/WEB-INF/classes
>      [echo] *** executing postGoal of war:webapp
>      [copy] Copying 1 file to
> /private/tmp/maven-filter/target/myapp/WEB-INF/classes
>
> war:war:
>      [echo] Building WAR myapp
>      [jar] Building jar: /private/tmp/maven-filter/target/myapp.war
> BUILD SUCCESSFUL
> Total time: 5 seconds
> Finished at: Tue Apr 05 10:46:00 CEST 2005
>
>
> // file: project.xml
> <?xml version="1.0"?>
> <project>
>      <pomVersion>3</pomVersion>
>      <id>myapp</id>
>      <name>myapp</name>
>      <build>
>          <resources>
>              <resource>
>                  <filtering>true</filtering>
>                  <directory>src/conf</directory>
>                  <includes>
>                      <include>*.properties</include>
>                  </includes>
>              </resource>
>          </resources>
>      </build>
> </project>
>
>
> // file: maven.xml
> <project xmlns:maven="jelly:maven" xmlns:ant="jelly:ant">
>      <postGoal name="war:webapp">
>                  <echo message="*** executing postGoal of war:webapp"/>
>                  <ant:filter token="logfile"
> value="/opt/tomcat/logs/myapp.log">
>                  <ant:copy overwrite="true"
> file="target/myapp/WEB-INF/classes/log4j.properties"
> tofile="target/myapp/WEB-INF/classes/log4j.properties"/>
>                  </ant:filter>
>      </postGoal>
> </project>
>
>
> // file: src/conf/log4j.properties
> log4j.rootCategory=WARN
> # value of next line should be expanded
> log4j.appender.logfile.File=@logfile@
> log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
> log4j.appender.logfile.DatePattern='.'yyyy-MM-dd'.log'
> log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
> log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - <%m>%n
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

--
Kenney Westerhof
http://www.neonics.com
GPG public key: http://www.gods.nl/~forge/kenneyw.key

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org