I'm new to Maven, and have a couple questions that I've not been able to
answer from the documentation on the site so far, so I thought I'd put
them out here.
-What I'm trying to do
Basically, I have the Maven 1 maven.xml file copied below (which, as you
can see, actually does a lot of its work via Ant call-throughs), and
have been assigned to convert the project to Maven 2. I've pasted the
contents of maven.xml below, at the bottom of the message. Basically,
the idea was to have 3 goals: live1, live2 (identical except for server
names--we run the app on a small cluster), and dev. Each has its own
property file, which is loaded into Maven's properties, and then used to
fill in various tokens in config files. It seems like "goals" are gone
in Maven 2, so I'm trying to replace that idea with different profiles,
but I'm encountering a couple of problems in the conversion.
-Questions
First, is there a comprehensive list of the tokens that are
automatically set in Maven 2? I'm talking about things like ${basedir},
which is the only one I've been able to uncover so far, that maven
assigns values to without needed to read them from a file somewhere. I'm
loooking especially for a Maven 2 equivalent to ${maven.war.webapp.dir},
which apparently was set in the Maven 1 war plugin, but not in the Maven
2 version. I assume it's still there, but I don't see anything to
indicate what it's called now.
Second, as I mentioned, the old goals loaded their particular properties
files into Maven. This is where things like ${email.reports} come from
in the copy/paste below. It seems to use ant:run to load the files that
way, which apparently brings the properties into Maven (not Ant)? That
seems strange and unintuitive, but that's the impression I get. The same
peculiar behavior does not appear to happen when I use Maven2's ant:run
to perform the same task. So, is there a way to get Maven to read a
standard Java properties file and make those available for ${} tokens?
Note that I cannot use <filter>, because I need those substitutions
available in pom.xml
Thanks,
Dan Allen
-The file I'm trying to convert
<?xml version="1.0" encoding="UTF-8"?>
<!-- Old Maven 1 maven.xml file. Works, but I'm trying to convert to
Maven 2. -->
<project default="dev"
xmlns:j="jelly:core"
xmlns:util="jelly:util"
xmlns:ant="jelly:ant">
<!--
Setup the log4j.properties by copying the correct one to
log4j.properties in target directory
and replacing the path token
-->
<preGoal name="java:jar-resources">
<ant:echo message="${maven.war.webapp.dir}" />
<ant:echo message="${maven.src.dir}" />
<ant:filter token="tomcat.home" value="${tomcat.home}" />
<ant:copy file="${maven.src.dir}/conf/${log4j.properties.file}"
tofile="${maven.war.webapp.dir}/WEB-INF/classes/log4j.properties"
overwrite="true" filtering="true" />
<ant:copy
file="${maven.src.dir}/conf/hibernate/${hibernate.properties.file}"
tofile="${maven.war.webapp.dir}/WEB-INF/classes/hibernate.properties"
overwrite="true" filtering="true" />
<ant:filter token="email.business" value="${email.business}" />
<ant:filter token="spreadsheet.storage"
value="${spreadsheet.storage}" />
<ant:filter token="email.reports" value="${email.reports}" />
<ant:filter token="host.url" value="${host.url}" />
<ant:filter token="email.alerts.system"
value="${email.alerts.system}" />
<ant:filter token="daemon.rv" value="${daemon.rv}" />
<ant:copy file="${maven.src.dir}/webapp/WEB-INF/web.xml"
tofile="${maven.war.webapp.dir}/WEB-INF/web.xml"
overwrite="true" filtering="true" />
</preGoal>
<!--
Export the SQL for Hibernate tables
-->
<postGoal name="war:webapp">
<attainGoal name="hibernate:schema-export" />
</postGoal>
<!--
Configures Tomcat (server.xml and Context insurancederiv.xml)
-->
<goal name="configureDevTomcat" prereqs="war:init"> <!-- war:init
sets maven.war.webapp.dir -->
<ant:filter token="target.home" value="${maven.war.webapp.dir}"
/>
<ant:copy file="context.xml"
tofile="${tomcat.home}/conf/Catalina/${host}/insurancederiv.xml"
overwrite="true" filtering="true" />
<ant:filter token="host" value="${host}" />
<ant:copy file="server.xml"
tofile="${tomcat.home}/conf/server.xml"
overwrite="true" filtering="true" />
</goal>
<!--
Development target
-->
<goal name="dev">
<j:set var="log4j.properties.file" value="log4j.dev.properties"
/>
<j:set var="hibernate.properties.file"
value="hibernate.properties.dev" />
<ant:property file="build.dev.properties" />
<attainGoal name="war:webapp" />
<attainGoal name="configureDevTomcat" />
</goal>
<!--
Live server target
-->
<goal name="live" >
<ant:fail unless="build.properties.file" message="This target
should be run via live1 or live2, not directly" />
<ant:echo message="Now undeploy the web app via the
manager" />
<attainGoal name="clean" />
<attainGoal name="war:init" /> <!-- Sets up maven.war.*
properties -->
<j:set var="log4j.properties.file" value="log4j.live.properties"
/>
<j:set var="hibernate.properties.file"
value="hibernate.properties.live" />
<ant:property file="${build.properties.file}" />
<ant:filter token="target.home"
value="${tomcat.home}/webapps/${pom.artifactId}" />
<ant:copy file="context.xml"
tofile="${maven.war.webapp.dir}/META-INF/context.xml"
overwrite="true" filtering="true" />
<attainGoal name="war:webapp" />
<attainGoal name="war:war" />
</goal>
<goal name="live2">
<j:set var="build.properties.file"
value="build.live2.properties" />
<attainGoal name="live" />
</goal>
<goal name="live1">
<j:set var="build.properties.file"
value="build.live1.properties" />
<attainGoal name="live" />
</goal>
</project>
--
This message may contain confidential, proprietary, or legally privileged
information. No confidentiality or privilege is waived by any transmission to
an unintended recipient. If you are not an intended recipient, please notify
the sender and delete this message immediately. Any views expressed in this
message are those of the sender, not those of any entity within the KBC
Financial Products group of companies (together referred to as "KBC FP").
This message does not create any obligation, contractual or otherwise, on the
part of KBC FP. It is not an offer (or solicitation of an offer) of, or a
recommendation to buy or sell, any financial product. Any prices or other
values included in this message are indicative only, and do not necessarily
represent current market prices, prices at which KBC FP would enter into a
transaction, or prices at which similar transactions may be carried on KBC FP's
own books. The information contained in this message is provided "as is",
without representations or warranties, express or implied, of any kind. Past
performance is not indicative of future returns.