You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Rick Genter <rg...@interactions.net> on 2011/04/19 23:11:26 UTC

Dynamically generating class names with archetype

I'm building an archetype for generating Maven projects for our custom application framework. Everything is working but the generated project always has the same class names and annotations. I would like to be able to dynamically specify those names/annotations.

For example, I can specify my Java file (src/main/resources/archetype-resources/src/main/java/ClientApp.java) like this:

package ${packageName};

// imports go here...

@OurAnnotation(client="Client", application="ClientApp", version="1.0.0-SNAPSHOT")
public class ClientApp extends OurBaseClass {
...
}

but what I'd like to do is something like this:

package ${packageName};

// imports go here...

@OurAnnotation(client="${client}", application="${clientApp}", version="${clientAppVersion}")
public class ${clientApp} extends OurBaseClass {
...
}

I tried the above and using:

mvn archetype:generate -DarchetypeGroupId=... -DarchetypeArtifactId=... -DarchetypeVersion=... -Dclient=Acme -DclientApp=HelloWorld6 -DclientAppVersion=1.0.0-SNAPSHOT -DgroupId=net.interactions.example -Dversion=0.0.1-SNAPSHOT -DartifactId=hello-world-6

my generated ClientApp.java file had the correct package name (net.interactions.example), but none of the other substitutions were performed. Also, I'd need the generated file itself to have the correct name (${clientApp}.java). I'd have preferred that the generated file be named "HelloWorld6.java" and have the content:

package net.interactions.example;

// imports go here...

@OurAnnotation(client="Acme", application="HelloWorld6", version="0.0.1-SNAPSHOT")
public class HelloWorld6 extends OurBaseClass {
...
}


Is what I want to do possible?
--
Rick Genter
rgenter@interactions.net



*******************************************************************************
This e-mail and any of its attachments may contain Interactions Corporation
proprietary information, which is privileged, confidential, or subject to
copyright belonging to the Interactions Corporation. This e-mail is intended
solely for the use of the individual or entity to which it is addressed. If you
are not the intended recipient of this e-mail, you are hereby notified that any
dissemination, distribution, copying, or action taken in relation to the
contents of and attachments to this e-mail is strictly prohibited and may be
unlawful. If you have received this e-mail in error, please notify the sender
immediately and permanently delete the original and any copy of this e-mail and
any printout. Thank You. 
*******************************************************************************


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


Re: Dynamically generating class names with archetype

Posted by Dirk Olmes <di...@xanthippe.ping.de>.
On 04/19/2011 11:11 PM, Rick Genter wrote:
> I'm building an archetype for generating Maven projects for our
> custom application framework. Everything is working but the generated
> project always has the same class names and annotations. I would like
> to be able to dynamically specify those names/annotations.
[...]
> but what I'd like to do is something like this:
> 
> package ${packageName};
> 
> // imports go here...
> 
> @OurAnnotation(client="${client}", application="${clientApp}",
> version="${clientAppVersion}") public class ${clientApp} extends
> OurBaseClass { ... }
> 
> I tried the above and using:
> 
> mvn archetype:generate -DarchetypeGroupId=...
> -DarchetypeArtifactId=... -DarchetypeVersion=... -Dclient=Acme
> -DclientApp=HelloWorld6 -DclientAppVersion=1.0.0-SNAPSHOT
> -DgroupId=net.interactions.example -Dversion=0.0.1-SNAPSHOT
> -DartifactId=hello-world-6
> 
> my generated ClientApp.java file had the correct package name
> (net.interactions.example), but none of the other substitutions were
> performed. Also, I'd need the generated file itself to have the
> correct name (${clientApp}.java). I'd have preferred that the
> generated file be named "HelloWorld6.java" and have the content:

Yes this is possible. Name the Java class in the archetype
__clientApp__.java and the archetype should fill in the proper variable
name. You need to specify the clientApp property in the
archetype-metadata.xml to enable the substitution.

-dirk

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


Re: Dynamically generating class names with archetype

Posted by Ryan Connolly <ry...@gmail.com>.
At the top of that page there is a link to a new archetype descriptor.  Have
a look there.
On Apr 19, 2011 6:14 PM, "Rick Genter" <rg...@interactions.net> wrote:
> On Apr 19, 2011, at 3:05 PM, Ryan Connolly wrote:
>
>> Hi have you defined these properties in an archetype descriptor?
>>
>> http://maven.apache.org/guides/mini/guide-creating-archetypes.html
>
> According to the documentation at:
>
> http://maven.apache.org/archetype/archetype-common/archetype.html
>
> the only elements supported by <archetype> are <id>, <allowPartial>,
<sources>, <resources>, <testSources>, <testResources> and <siteResources>.
Where would I put the definitions of those properties?
>
> --
> Rick Genter
> rgenter@interactions.net
>
>
>
>
*******************************************************************************
> This e-mail and any of its attachments may contain Interactions
Corporation
> proprietary information, which is privileged, confidential, or subject to
> copyright belonging to the Interactions Corporation. This e-mail is
intended
> solely for the use of the individual or entity to which it is addressed.
If you
> are not the intended recipient of this e-mail, you are hereby notified
that any
> dissemination, distribution, copying, or action taken in relation to the
> contents of and attachments to this e-mail is strictly prohibited and may
be
> unlawful. If you have received this e-mail in error, please notify the
sender
> immediately and permanently delete the original and any copy of this
e-mail and
> any printout. Thank You.
>
*******************************************************************************
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

Re: Dynamically generating class names with archetype

Posted by Rick Genter <rg...@interactions.net>.
On Apr 19, 2011, at 3:05 PM, Ryan Connolly wrote:

> Hi have you defined these properties in an archetype descriptor?
> 
> http://maven.apache.org/guides/mini/guide-creating-archetypes.html

According to the documentation at:

http://maven.apache.org/archetype/archetype-common/archetype.html

the only elements supported by <archetype> are <id>, <allowPartial>, <sources>, <resources>, <testSources>, <testResources> and <siteResources>. Where would I put the definitions of those properties?

--
Rick Genter
rgenter@interactions.net



*******************************************************************************
This e-mail and any of its attachments may contain Interactions Corporation
proprietary information, which is privileged, confidential, or subject to
copyright belonging to the Interactions Corporation. This e-mail is intended
solely for the use of the individual or entity to which it is addressed. If you
are not the intended recipient of this e-mail, you are hereby notified that any
dissemination, distribution, copying, or action taken in relation to the
contents of and attachments to this e-mail is strictly prohibited and may be
unlawful. If you have received this e-mail in error, please notify the sender
immediately and permanently delete the original and any copy of this e-mail and
any printout. Thank You. 
*******************************************************************************


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


Re: Dynamically generating class names with archetype

Posted by Ryan Connolly <ry...@gmail.com>.
Hi have you defined these properties in an archetype descriptor?

http://maven.apache.org/guides/mini/guide-creating-archetypes.html
 On Apr 19, 2011 5:11 PM, "Rick Genter" <rg...@interactions.net> wrote:
> I'm building an archetype for generating Maven projects for our custom
application framework. Everything is working but the generated project
always has the same class names and annotations. I would like to be able to
dynamically specify those names/annotations.
>
> For example, I can specify my Java file
(src/main/resources/archetype-resources/src/main/java/ClientApp.java) like
this:
>
> package ${packageName};
>
> // imports go here...
>
> @OurAnnotation(client="Client", application="ClientApp",
version="1.0.0-SNAPSHOT")
> public class ClientApp extends OurBaseClass {
> ...
> }
>
> but what I'd like to do is something like this:
>
> package ${packageName};
>
> // imports go here...
>
> @OurAnnotation(client="${client}", application="${clientApp}",
version="${clientAppVersion}")
> public class ${clientApp} extends OurBaseClass {
> ...
> }
>
> I tried the above and using:
>
> mvn archetype:generate -DarchetypeGroupId=... -DarchetypeArtifactId=...
-DarchetypeVersion=... -Dclient=Acme -DclientApp=HelloWorld6
-DclientAppVersion=1.0.0-SNAPSHOT -DgroupId=net.interactions.example
-Dversion=0.0.1-SNAPSHOT -DartifactId=hello-world-6
>
> my generated ClientApp.java file had the correct package name
(net.interactions.example), but none of the other substitutions were
performed. Also, I'd need the generated file itself to have the correct name
(${clientApp}.java). I'd have preferred that the generated file be named
"HelloWorld6.java" and have the content:
>
> package net.interactions.example;
>
> // imports go here...
>
> @OurAnnotation(client="Acme", application="HelloWorld6",
version="0.0.1-SNAPSHOT")
> public class HelloWorld6 extends OurBaseClass {
> ...
> }
>
>
> Is what I want to do possible?
> --
> Rick Genter
> rgenter@interactions.net
>
>
>
>
*******************************************************************************
> This e-mail and any of its attachments may contain Interactions
Corporation
> proprietary information, which is privileged, confidential, or subject to
> copyright belonging to the Interactions Corporation. This e-mail is
intended
> solely for the use of the individual or entity to which it is addressed.
If you
> are not the intended recipient of this e-mail, you are hereby notified
that any
> dissemination, distribution, copying, or action taken in relation to the
> contents of and attachments to this e-mail is strictly prohibited and may
be
> unlawful. If you have received this e-mail in error, please notify the
sender
> immediately and permanently delete the original and any copy of this
e-mail and
> any printout. Thank You.
>
*******************************************************************************
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>