You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Werner Punz <we...@gmail.com> on 2009/10/13 16:17:40 UTC

Maven archtypes and custom parameters

Hello everyone I am new to the maven archetype programming but I ran 
instantly into a problem.

I have a custom archetype which should generate some java code
the java file has something like public static String ${myvar}

and I try to generate the code from the artefact via mvn 
archetype:create .... -Dmyvar=myValue

but maven then complains:

org.apache.velocity.ReferenceException ${myvar} is not a valid reference.
The funny thin is that the standard parameters are passed down correctly 
such as artifactId or groupId
so something like public static String ${groupId}
is resolved correctly.

Does anyone know how to resolve this how to pass down custom parameters
which then later are picked up internally by veclocity?


Werner


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


Re: Maven archtypes and custom parameters

Posted by Werner Punz <we...@gmail.com>.
Martin Höller schrieb:
> On Tuesday 13 October 2009 Werner Punz wrote:
>> Hello everyone I am new to the maven archetype programming but I ran
>> instantly into a problem.
>>
>> I have a custom archetype which should generate some java code
>> the java file has something like public static String ${myvar}
>>
>> and I try to generate the code from the artefact via mvn
>> archetype:create .... -Dmyvar=myValue
>>
>> but maven then complains:
>>
>> org.apache.velocity.ReferenceException ${myvar} is not a valid reference.
>> The funny thin is that the standard parameters are passed down correctly
>> such as artifactId or groupId
>> so something like public static String ${groupId}
>> is resolved correctly.
> 
> I'm a archetype newbie but I think you should define something like this in 
> archetype-metadata.xml:
> 
>   <requiredProperties>
>     <requiredProperty key="myvar">
>       <defaultValue>some-default</defaultValue>
>     </requiredProperty>
>   </requiredProperties>
> 
> See also 
> http://maven.apache.org/plugins/maven-archetype-plugin/examples/create-with-property-file.html
> 
Actually I did that but the templates still do not pick the value up 
unfortuntately. Never mind I simply programmed my own tool which does 
exactly what I need, since I have to trigger all this outside of maven 
anyway it was not a big loss except for a few hours of programming time.


Werner



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


Re: Maven archtypes and custom parameters

Posted by Martin Höller <ma...@xss.co.at>.
On Tuesday 13 October 2009 Werner Punz wrote:
> Hello everyone I am new to the maven archetype programming but I ran
> instantly into a problem.
>
> I have a custom archetype which should generate some java code
> the java file has something like public static String ${myvar}
>
> and I try to generate the code from the artefact via mvn
> archetype:create .... -Dmyvar=myValue
>
> but maven then complains:
>
> org.apache.velocity.ReferenceException ${myvar} is not a valid reference.
> The funny thin is that the standard parameters are passed down correctly
> such as artifactId or groupId
> so something like public static String ${groupId}
> is resolved correctly.

I'm a archetype newbie but I think you should define something like this in 
archetype-metadata.xml:

  <requiredProperties>
    <requiredProperty key="myvar">
      <defaultValue>some-default</defaultValue>
    </requiredProperty>
  </requiredProperties>

See also 
http://maven.apache.org/plugins/maven-archetype-plugin/examples/create-with-property-file.html

hth
- martin