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/ 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/


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,


Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

Leave a Reply

8 + = sixteen

Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

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

Get ready to Rock!
You can download the complementary eBooks using the links below: