Home » Java » Enterprise Java » Building your own GWT Spring Maven Archetype

About Panagiotis Paterakis

Panagiotis Paterakis
Panagiotis is an open source enthusiast. In the morning he works as a freelancer implementing a wide variety of applications/services for the telecom industry (teleconference, NGIN, SOA). As a night job he craves to contribute to several open source projects. His latest activity is a forthcoming open source software that will bring the non trivial applications closer to the cloud

Building your own GWT Spring Maven Archetype

Hello everyone,

While watching  this really interesting articles by Justin about Spring and GWT,i thought that it would be extremely useful to show how to build your own custom maven archetype .The archetype we will present is based on the last project of Justin and includes various technologies like Spring,GWT,AspectJ,HornetQ and Infinispan.

Enough talking ,let’s get our hands dirty now.

Preparation of the archetype.

First you must have a template project that you will use to build your archetype.In our presentation you will find Justin project here.

Change directory to the root directory of the project and run the following command.

mvn archetype:create-from-project

After the completion of the command you will find a new project that is generated at the following location ${project_home}/target/generated-sources/archetype.Its a complete maven archetype project that you can customize for your needs.

  • At folder src/main/resources/META-INF/maven you will find archetype-metadata.xml which is the descriptor of the archetype.
  • At folder src/main/resources/archetype-resources is the template project that is going to be generated.

Customization of archetype.

Maven archetypes use apache velocity to generate their code. You can access velocity variables in a file by setting the following constants at the top of a file:

#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )

Then you have access to maven properties like artifactId by using this syntax ${artifactId}.Also you can use the following syntax __artifactId__ to access the value of a parameter.

The basic parameters that every archetype has are the following :

  • groupId
  • artifactId
  • version
  • package

Also you can set as many variables as you want at the archetype-metadata.xml using the following syntax :


please notice that each time you add a variable you should edit src/test/resources/projects/basic/archetype.properties and add your parameter.



In our example we performed the following changes:

At src/main/resources/META-INF/maven/archetype-metadata.xml

      <requiredProperty key="db">
      <requiredProperty key="dburl">
      <requiredProperty key="dbusername">
      <requiredProperty key="dbpassword">
      <requiredProperty key="cache">

At src/test/resources/projects/basic/archetype.properties


At src/main/resources/archetype-resources/pom.xml

#if( $db == "derby" )
    #elseif( $db == "mysql" )


            <!-- here the phase you need -->

At src/main/resources/archetype-resources/src/main/webapp/WEB-INF/applicationContext.xml

#if($db == "mysql")	
	<bean id="dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
		init-method="init" destroy-method="close">
		<property name="uniqueResourceName" value="javacodegeeks" />
		<property name="xaDataSourceClassName"
			value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
		<property name="xaProperties">
				<prop key="URL">${dburl}</prop>
				<prop key="user">${dbusername}</prop>
				<prop key="password">${dbpassword}</prop>
		<property name="maxPoolSize" value="50" />
		<property name="minPoolSize" value="20" />
	<bean id="dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
		init-method="init" destroy-method="close">
		<property name="uniqueResourceName" value="javacodegeeks" />
		<property name="xaDataSourceClassName" value="org.apache.derby.jdbc.EmbeddedXADataSource" />
		<property name="xaProperties">
        		<prop key="databaseName">${dburl}</prop>
        		<prop key="createDatabase">create</prop>
		<property name="maxPoolSize" value="50" />
		<property name="minPoolSize" value="20" />

At src/main/resources/archetype-resources/src/main/resources/META-INF/persistence.xml

#if($cache == "y")
			<property name="hibernate.cache.use_second_level_cache" value="true"/>
			<property name="hibernate.cache.use_query_cache" value="true"/>
			<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/>
			<property name="hibernate.cache.infinispan.entity.eviction.strategy" value= "LRU"/>
			<property name="hibernate.cache.infinispan.entity.eviction.wake_up_interval" value= "2000"/>
			<property name="hibernate.cache.infinispan.entity.eviction.max_entries" value= "5000"/>
			<property name="hibernate.cache.infinispan.entity.expiration.lifespan" value= "60000"/>
			<property name="hibernate.cache.infinispan.entity.expiration.max_idle" value= "30000"/>

			<property name="hibernate.cache.use_second_level_cache" value="false"/>^M
                        <property name="hibernate.cache.use_query_cache" value="false"/>^M


Rename com/javacodegeeks/gwtspring/public folder to __artifactId__ .

Installing and Running the archetype

To install the archetype go to the root folder of the archetype and type.

mvn install

This should create ~/.m2/archetype-catalog.xml file that you can import to eclipse if you are an eclipse an m2eclipse user.

To run the archetype run the following.

mvn archetype:generate -DarchetypeCatalog=local -DarchetypeGroupId=com.javacodegeeks -DarchetypeArtifactId=gwtspring-archetype

Or create a new maven project in eclispe and select the archetype from the local catalog you imported from ~/.m2/archetype-catalog.xml .

*** Notice that the archetype might be snapshot and you should check “Include snapshots archetypes”.

The source code of the archetype is available here.

Hope you enjoy this article,

Best regards,


Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

and many more ....


Leave a Reply

Your email address will not be published. Required fields are marked *


Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.