[EMAIL PROTECTED] wrote on 18/06/2008 16:50:05:
> Can we make use of our own properties/variables in archetypes?
>
> The m2eclipse plugin allows us to define properties to be used at
arcetype
> generation time.
>
> The problem is, I've not see a single references as to _how_ to do
> this!???
>
> For example:
>
> <dependency>
> <groupId>${groupId}</groupId>
> <artifactId>${projectName}Web</artifactId>
> <version>1.0-SNAPSHOT</version>
> <type>war</type>
> </dependency>
>
> I would like to be able to define the value of the variable projectName,
> so, if I defined projectName = Blah, it would expand to:
>
> <artifactId>BlahWeb</artifactId>
>
> -Chris
To answer my own question (with a little help from some - thanks!):
Create a file called archetype-metadata.xml in the
\src\main\resources\META-INF\maven directory, and put this into it:
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor name="basic-ear">
<fileSets>
<fileSet filtered="true" packaged="false">
<directory></directory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileSets>
<requiredProperties>
<requiredProperty key="projectName" />
</requiredProperties>
</archetype-descriptor>
That will process and generate what is needed.
Now, when you call the generate stage, you need to define the the property
"projectName" as a system property, by defining it as a system property:
mvn archetype:generate
-Darchetype.interactive=false
-DarchetypeCatalog=local
-DarchetypeGroupId=au.com.warpspeed.archetypes
-DarchetypeArtifactId=basic-ear
-DarchetypeVersion=1.0
-DgroupId=au.com.warpspeed.test
-DartifactId=SampleEAR
-Dversion=1.0-SNAPSHOT
-DprojectName=Sample
If you get an error similar to this:
[INFO]
------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] : org.apache.maven.archetype.exception.ArchetypeNotConfigured:
Archetype au.com.warpspeed.archetypes:build:1.0 is
not configured
Archetype au.com.warpspeed.archetypes:build:1.0 is not configured
Archetype au.com.warpspeed.archetypes:build:1.0 is not configured
It means that the property has not been specified. Hope this helps.
The full doco can be found at:
http://maven.apache.org/plugins/maven-archetype-plugin/specification/archetype-metadata.html
-Chris
**********************************************************************
CAUTION - This message is intended for the addressee named above. It may
contain privileged or confidential information.
If you are not the intended recipient of this message you must:
- Not use, copy, distribute or disclose it to anyone other than the addressee;
- Notify the sender via return email; and
- Delete the message (and any related attachments) from your computer
immediately.
Internet emails are not necessarily secure. Australian Associated Motors
Insurers Limited ABN 92 004 791 744 (AAMI), and its related entities, do not
accept responsibility for changes made to this message after it was sent.
Unless otherwise stated, views expressed within this email are the author's own
and do not represent those of AAMI.
**********************************************************************