How to create Java-J2EE project using AndroMDA?

create Java-J2EE project using AndroMDA
Spider Web Model (gradders52, Flickr)

AndroMDA (pronounced as “Andromeda”) is an extensible generator framework that adheres to the Model Driven Architecture (MDA) paradigm.  It transforms UML models into deployable components for Java/J2EE & Microsoft .NET; using AndroMDA means one main thing:write less code.  Not only that, AndroMDA also lets you create better applications and maintain order on large projects.  AndroMDA enforces best practices and lets developers focus on high level problems.

During development of large applications, most architects and developers already create class diagrams and data diagrams.  These diagrams are usually made in tools like Microsoft Visio, and the resulting artifacts are static pictures.  When code changes, the diagrams must be updated.  With AndroMDA, these diagrams become a living part of your application – they are used to generate large portions of your application, and hence always reflect the current state of the system. When you need to modify your application, you change the model first, regenerate the code, and then add or update custom code as necessary.

“AndroMDA Tool can be used for Java/J2EE and Microsoft .NET based projects”

AndroMDA provides several cartridges out-of-the-box:

  • The Hibernate and Spring cartridges generate robust service and data layers for your Java/J2EE based application
  • The NHibernate and NSpring cartridges generate robust service and data layers for your .NET based application
  • JSF cartridges generate robust presentation layer
  • BPM4Struts(Business Process Modeling for Struts) – this cartridge is to generate Struts web pages from an input UML model in which the flow of the application is modeled
  • jBPMworkflow engine – this cartridge is able to generate process definitions and handlers from UML activity graphs
  • EJB & EJB3
  • Java
  • WebService – generates WSDD (Web Service Descriptor files and WSDL) files for Apache Axis and Apache CXF also generates WebService Client for consuming these generated WebService
  • XmlSchema – used for generating an XML Schema from a class model. It will be used to WebService marshalling and unmarshalling

Article goal is provide detailed info for “create Java-J2EE project using AndroMDA


When to use AndroMDA?

With highly useful MDA tool (AndroMDA uses EMF to generate the code based on architecture models), you must know when to make use of it.  Use it wisely!

AndroMDA is a best choice

  • Starting a new project, or completely rewriting a project/layer of an existing application
  • Want to save time by generating as much code as possible
  • Building an application that stores its data in a database
  • Familiar with UML Modeling tools and want to create more than just pretty pictures

AndroMDA might not be the best choice

  • Application uses an existing database that cannot be easily mapped to an object model (for example, it does not use primary keys and object relationships are not clear)
  • Already have a mature application with existing business objects and the incremental effort to model existing components is too high to provide enough value

Benefits of Model Driven Architecture (MDA) & Model Driven Development (MDD)

There are several benefits using MDA/MDD in larger applications:

  • Lower the risk of large applications
  • Less error-prone
  • Empowers domain experts
  • Brings solid structure/surface between business and IT
  • Simplified development
  • Enforces architecture
  • Enables to focus on business goals instead of technology
  • Increase in Quality of the application
  • Cost effective – leverage open source
  • Provides up-to-date documentation – Model reflects up-to-date application structure

Assumption

Now we will starting project generation steps so, I assume Maven 2.2.1 or above version; already installed on your machine.


Generating J2EE based application using AndroMDA tool

Step 1

Follow this article How to generate Maven based Java/J2EE Project using Archetype? to create maven sample application.  Because we have to download AndroMDA project generation plugin to local maven repo

Note: AndroMDA version 3.4 has been released on Sep 08, 2012.  Please use 3.4 instead of 3.4-SNAPSHOT in below steps in the article, Thanks.

Step 2

Go to the created sampleapplication directory, as per example directory is /Users/jeeva/Documents/my-contributions/generic-repo/sampleapplication and Edit the pom.xml; add the below entry after end of </dependencies> tag.  Don’t forget to save the edited file.

<build>
	<defaultGoal>compile</defaultGoal>
	<plugins>
		<plugin>
			<groupId>org.andromda.maven.plugins</groupId>
			<artifactId>andromdapp-maven-plugin</artifactId>
			<version>3.4</version>
		</plugin>
	</plugins>
</build>

Step 3

Build the sampleapplication project, run mvn without any arguments.  Ensure the command execution completes successfully by displaying the BUILD SUCCESSFUL message.  If you face any issues building sampleapplication, please click here (Tips below)

mac-book-pro:sampleapplication jeeva$ mvn
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building sampleapplication
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] snapshot org.andromda.maven.plugins:andromdapp-maven-plugin:3.4-SNAPSHOT: checking for updates from sonatype
[INFO] snapshot org.andromda.maven.plugins:andromdapp-maven-plugin:3.4-SNAPSHOT: checking for updates from jboss
Downloading: http://oss.sonatype.org/content/groups/public/org/andromda/maven/plugins/andromdapp-maven-plugin/3.4-SNAPSHOT/andromdapp-maven-plugin-3.4-20120529.084949-2.pom

[INFO] snapshot org.andromda.maven.plugins:andromda-maven-plugins:3.4-SNAPSHOT: checking for updates from sonatype
[INFO] snapshot org.andromda.maven.plugins:andromda-maven-plugins:3.4-SNAPSHOT: checking for updates from jboss

Downloading: http://oss.sonatype.org/content/groups/public/org/andromda/maven/plugins/andromda-maven-plugins/3.4-SNAPSHOT/andromda-maven-plugins-3.4-20120529.074113-2.pom

[INFO] snapshot org.andromda:andromda:3.4-SNAPSHOT: checking for updates from sonatype
[INFO] snapshot org.andromda:andromda:3.4-SNAPSHOT: checking for updates from jboss

Downloading: http://oss.sonatype.org/content/groups/public/org/andromda/andromda/3.4-SNAPSHOT/andromda-3.4-20120529.073737-2.pom
...
...
... [downloading required artifacts and andromda UML profiles]
...
...
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to /Users/jeeva/Documents/my-contributions/generic-repo/sampleapplication/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 minutes 35 seconds
[INFO] Finished at: Tue Jun 26 17:01:48 GMT+05:30 2012
[INFO] Final Memory: 12M/265M
[INFO] ------------------------------------------------------------------------

mac-book-pro:sampleapplication jeeva$

Step 4

Now AndroMDA maven plugin have been download into your local maven repo and we are ready to create a project.  Execute the below maven command to create AndroMDA J2EE Application

mvn org.andromda.maven.plugins:andromdapp-maven-plugin:3.4:generate

Step 5

Maven will download required POM and jar files then AndroMDA plugin will start the interactive mode for application generation

mac-book-pro:sampleapplication jeeva$ mvn org.andromda.maven.plugins:andromdapp-maven-plugin:3.4-SNAPSHOT:generate

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building sampleapplication
[INFO] task-segment: [org.andromda.maven.plugins:andromdapp-maven-plugin:3.4-SNAPSHOT:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
Downloading: http://oss.sonatype.org/content/groups/public/commons-io/commons-io/2.3/commons-io-2.3.pom

[INFO] Unable to find resource 'commons-io:commons-io:pom:2.3' in repository sonatype (http://oss.sonatype.org/content/groups/public)
Downloading: http://www.andromda.org/maven2/commons-io/commons-io/2.3/commons-io-2.3.pom

[INFO] Unable to find resource 'commons-io:commons-io:pom:2.3' in repository andromda (http://www.andromda.org/maven2)
Downloading: http://repo1.maven.org/maven2/commons-io/commons-io/2.3/commons-io-2.3.pom

2K downloaded&nbsp; (commons-io-2.3.pom)
...
... [downloading required pom and jar files]
...

Choose your application type (j2ee or richclient)

[INFO] [andromdapp:generate {execution: default-cli}]
INFO [AndroMDA] discovered andromdapp type --> 'j2ee'
INFO [AndroMDA] discovered andromdapp type --> 'richclient'

Please choose the type of application to generate [j2ee, richclient]
j2ee

Provide base directory for project generation and project creator First Name and Last Name

Please enter the parent directory of your new application directory (i.e. C:/Workspaces):
/Users/jeeva/Documents/my-contributions/generic-repo/

Please enter your first and last name (i.e. Chad Brandon):
Jeevanandam Madanagopal

Now choosing a modeling tool for your project

Which kind of modeling tool will you use? (uml1.4 or uml2 for .xml.zip/.xml/.xmi/.zargo files, emf-uml22 for .uml files, rsm7 for .emx files) [uml1.4, uml2, emf-uml22, rsm7]:

uml2

Provide Maven project description, Maven artifactId of your project, project version, Maven groupId (root package of the project)

Please enter the name (maven project description) of your J2EE project (i.e. Animal Quiz):
Sample J2EE AndroMDA Application

Please enter an id (maven artifactId) for your J2EE project (i.e. animalquiz):
andromdaapplication

Please enter a version for your project (i.e. 1.0-SNAPSHOT):
1.0-SNAPSHOT

Please enter the root package name (maven groupId) for your J2EE project (i.e. org.andromda.samples.animalquiz):
com.myjeeva.andromda.samples

Provide project packaging type

Would you like an EAR or standalone WAR? [ear, war]:
war

Choosing Transactional/Persistence cartridge of project

Please enter the type of transactional/persistence cartridge to use (enter 'none' if you don't want to use one) [spring, none]:
spring

Choosing a programming language of project (Java or Groovy)

Please enter the programming language to be used in service and dao implementations [java 1="groovy" language=","][/java]:
java

Choosing a wide range of Database backend for persistence layer (Oracle, Microsoft SQL, DB2, Informix, My SQL, Sybase, Postgres, Derby, etc.)

Please enter the database backend for the persistence layer [h2, hypersonic, mysql, oracle, db2, informix, mssql, pointbase, postgres, sybase, sabdb, progress, derby]:
oracle

Whether workflow engine capabilities required in project or not

Will your project need workflow engine capabilities? (it uses jBPM and Hibernate3)? [yes, no]:
yes

Whether project will have web user interface or not; If answer is Yes, you will get option for User Interface selection like JSF or Struts Will your project have a web user interface? [yes, no]:
no

Choice of exposing project services as WebService or not

Would you like to be able to expose your services as web services? [yes, no]:
yes

Selecting project WebService stack (Axis, CXF, Sun JAX-WS)

Would you like to use Axis, XFire, CXF, or Sun's Jax-WS as your SOAP Stack? [axis, xfire, cxf, jaxws]:
cxf

Selecting JAX-WS REST producer/consumer media type

What is your JAX-WS REST provider/consumer media type?
(none for JAX-WS only, xml for JAX-RS only, or appxml, json, atom, plain, multipart, fastinfoset, yaml) [none, xml, appxml, json, atom, plain, fastinfoset, yaml, multipart]:
json

Finally, would like to use embedded jetty web server or not

Would you like to use the embedded Jetty web server (Maven plugin)? [yes, no]:
no

Now AndroMDA will generate the Java/J2EE application from Archetype

-------------------------------------------------------------------------------------
G e n e r a t i n g  A n d r o M D A  P o w e r e d  A p p l i c a t i o n
-------------------------------------------------------------------------------------
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/pom.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/CXF/pom.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/CXF/target/andromdaapplication-CXF-1.0-SNAPSHOT/WEB-INF/web.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/readme.txt'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/m2eclipse.bat'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/workflow/pom.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/common/pom.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/mda/pom.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/mda/build.properties'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/mda/src/main/uml/andromdaapplication.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/mda/src/main/config/andromda.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/mda/src/main/config/mappings/JavaMappings.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/mda/src/main/config/mappings/SpringMergeMappings.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/mda/build.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/mda/readme.txt'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/mda/.project'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/mda/log4j.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/core/pom.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/core/target/classes/META-INF/ejb-jar.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/webservice/pom.xml'
Output: 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/webservice/target/andromdaapplication-webservice-1.0-SNAPSHOT/WEB-INF/web.xml'
-------------------------------------------------------------------------------------
New application generated to --> 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/'
Instructions for your new application --> 'file:/Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/readme.txt'
-------------------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17 minutes 22 seconds
[INFO] Finished at: Tue Jun 26 17:22:52 GMT+05:30 2012
[INFO] Final Memory: 26M/265M
[INFO] ------------------------------------------------------------------------

mac-book-pro:sampleapplication jeeva$

Step 6

Most of the question form interactive mode of archetype are self explanatory. However there is one question “Which kind of modeling tool will you use? (uml1.4 or uml2 for .xml.zip/.xml/.xmi/.zargo files, emf-uml22 for .uml files, rsm7 for .emx files) [uml1.4, uml2, emf-uml22, rsm7]:”.

Based on your choice you can use following modeling tools:

  • MagicDraw UML Modeling (this is best bet for AndroMDA)
  • IBM Rational Software Modeler
  • ArgoUML

Step 7

Go to newly generate AndroMDA J2EE application directory and followed by directory called ‘mda’.  Now we have to get all the AndroMDA UML 2/UML 1.4 profiles for modeling

mac-book-pro:sampleapplication jeeva$ cd /Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/
mac-book-pro:andromdaapplication jeeva$ cd mda
mac-book-pro:mda jeeva$ mvn clean install

Note: If you get message as BUILD ERROR, Don’t worry currently our goal to download required AndroMDA profiles to local maven repo. This error occurred because, we have not yet done a UML modeling.

Step 8

Ready to start, project UML modeling for new created J2EE project.  Use Modeler tool of your choice mentioned in Step 6

Model file location: ${base-directory}/andromdaapplication/mda/src/main/uml/andromdaapplication.xml

For example: as per this article model location is /Users/jeeva/Documents/my-contributions/generic-repo/andromdaapplication/mda/src/main/uml/andromdaapplication.xml


Result

That’s it, now you have successfully created AndroMDA J2EE project (create Java-J2EE project using AndroMDA) and it’s ready to model and generate code.


Downloads

This article generated andromdaapplication has been checked-in to GitHub

git://github.com/jeevatkm/generic-repo.git

Also downloadable zip archive available click here!


Tips for Errors

Error 1

If you get following error, ensure your maven settings.xml has below settings. Else add it

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).

Project ID: org.andromda.maven.plugins:andromdapp-maven-plugin

Reason: POM 'org.andromda.maven.plugins:andromdapp-maven-plugin' not found in repository: Unable to download the artifact from any repository

org.andromda.maven.plugins:andromdapp-maven-plugin:pom:3.4-SNAPSHOT

from the specified remote repositories:
central (http://central)
for project org.andromda.maven.plugins:andromdapp-maven-plugin

Settings for correcting Error 1

<profile>
	<id>default</id>
	<activation>
		<activeByDefault>true</activeByDefault>
	</activation>
	<repositories>
		<repository>
			<id>sonatype</id>
			<name>Sonatype Repository</name>
			<url>http://oss.sonatype.org/content/groups/public</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
		<repository>
			<id>jboss</id>
			<name>JBoss Repository</name>
			<url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>sonatype</id>
			<name>Sonatype Repository</name>
			<url>http://oss.sonatype.org/content/groups/public</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>
</profile>

Reference: andromda.org