Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
484 views
in Technique[技术] by (71.8m points)

maven 2 - Simulating the Maven2 filter mechanism using Ant

I have a properties file, let say my-file.properties. In addition to that, I have several configuration files for my application where some information must be filled regarding the content of my-file.properties file.

my-file.properties:

application.version=1.0
application.build=42
user.name=foo
user.password=bar

Thus, in my configuration files, I will find some ${application.version}, ${user.name} that will be replaced by their value taken in the properties file...

When I build my application using Maven2, I only need to specify the properties file and say that my resources files are filtered (as in this answer to another problem). However, I need to achieve the same thing by using only Ant.

I've seen that Ant offers a filter task. However, it forces me to use the pattern @property.key@ (i.e. @user.name@ instead of #{user.name}) in my configuration files, which is not acceptable in my case.

How can I solve my problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think expandproperties is what you are looking for. This acts just like Maven2's resource filters.


INPUT

For instance, if you have src directory (one of many files):

<link href="${css.files.remote}/css1.css"/>

src/test.txt


PROCESS

And in my ANT build file we have this:

<project default="default">
   <!-- The remote location of any CSS files -->
   <property name="css.files.remote" value="/css/theCSSFiles" />     
   ...
   <target name="ExpandPropertiesTest">

      <mkdir dir="./filtered"/>

      <copy todir="./filtered">
         <filterchain>
            <expandproperties/>
         </filterchain>     

         <fileset dir="./src" />
      </copy>
   </target>
</project>

build.xml


OUTPUT

*When you run the ExpandPropertiesTest target you will have the following in your filtered directory: *

    <link href="/css/theCSSFiles/css1.css"/>

filtered/test.txt


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...