Tuesday, June 29, 2010

Speeding up Andromda

Andromda is a bit of a hog when you are trying to do a maven compile.  We have a pretty complex model, and we use Andromda to generate all of our backend classes.  On my machine our 'normal' maven build takes approximately 2 min and 45 secs to do the andromda generate, and compile the classes.  Acceptable after a model change, since I model relatively rarely.  Too much time when you are doing normal coding activities.

Here are a few tips:

You can do a:

Skip unit tests:
mvn -Dmaven.test.skip to skip unit tests.

Do an offline build:
mvn -o this will do an 'offline' build, saving the check of all of the SNAPSHOT dependencies.  Andromda has a lot of them!

Skip Andromda model validation:
mvn -Dvalidation=false  this skips the validation of the model, and will go right into the compile.  This saves about 45 seconds on my machine.


Use andromda server:
There is a mvn mda\pom.xml andromda:start-server
This loads a memory resident verion of andromda and loads the xml into memory.  This will monitor the model as well and auto-reload it into memory apon changes.  In a separate command window you can then issue your normal andromda commands, and it will trigger this 'server window' to perform the andromda portion of your build.  Everything seemed to work with this, but when I did my build I got some compile errors that I did not have doing the non server build.... maybe have a path issue or something... going to have to look into this further.  This method on my machine compiled in 30 seconds, saving 2mins 15 sec per build... so this will warrent some further investigation.  If anyone has any insight into the andromda server let me know.

Build only the modules you are working on:

You are supposed to be able to run
mvn -f core/pom.xml to compile just the core package, but this totally blows up for me due to dependencies in the common package etc.  Did not have time to frig with this ... again, any insight on getting this going, please let me know.

Friday, June 11, 2010

EJB3 - JBOSS - Andromda created -- deployment

OK.

So the ear built fine, now to get it to deploy properly...

I have installed JBOSS v5.0.1 on my machine.  Tried deploying the ear by copying it into:
%JBOSSDeployFolder%\server\default\deploy

Starting getting erros like:

error due to the following reason(s): org.jboss.xb.binding.JBossXBRuntimeException: Element {http://java.sun.com/xml/ns/javaee}jboss is not bound as a global element.




I realized that the jboss.xml file (located inside of the 'yourapp-core.jar' file) which is inside of the .ear had the wrong xml namespace defined.  To fix it you will need to modify the jboss.xml.vsl file, which is located in the cartridge.  As I mentioned in my previous blog post, I maintain a copy of the SNAPSHOT version to keep my changes from being overwritten...   to fix the xml namespace issue, I open my andromda-ejb3-cartridge-1.0-JBOSS.jar file (located in my maven local repository as described in previous blog post).  Modify the /templates/ejb3/config/jboss/jboss.xml.vsl file.  Change the tag to be:

 


I also had problems where JBOSS gave what is IMHO a really bad error message, it said:

* EJB CholesterolGoalDao has defined EJB2.x local component interface of com.wellnessrecord.domain.goals.CholesterolGoalDao but has no localHome; ; Incomplete EJB2.x View [JBMETA-130]

Which after some investigation, means that the ejb-jar.xml created by Andromda is outdated, and uses the old EJB 2.1 conventions...

This file has sections for each of your session beans of the form:

  
           
               
           

            UserServiceBean
            com.wellnessrecord.service.UserServiceRemote
            com.wellnessrecord.service.UserServiceBean
            Stateless
            Container
       


Well, as it turns out, in EJB3 you need the and tags to be of the form and

To fix, modify the file:  /andromda-ejb3-cartridge-1.0-JBOSS.jar\templates\ejb3\config\ejb-jar.xml file.  Replace all occurances of with , with , with and with


Run:
mvn clean
mvn install

Redeploy your .ear to JBOSS.

Friday, September 4, 2009

AndroMDA <> entities

AndroMDA is an excellent open source solution for auto-magically generating code from a UML model. This is a description of my experience trying out the <> stereotype. This stereotype appears to allow you to auto-generate data entry screens just by adding the <> stereotype to an entity.

My steps to generate a manageable entity:

Just a little background, I am developing EJB3 entities using JPA /Hibernate/Mysql.
My EJB/Servlet server is Sun Glassfish v2.1 running the Liferay Portal v5.2.3
Maven v2.0.9, Java JDK v1.6.0_13

'out of the box', Andromda will NOT generate any projects properly for Glassfish. I had to make a modified ejb3 cartridge which works on GLASSFISH. I am not going to describe what I had to do in this post, but will try to remember to detail that at a later time. If anyone needs that info, or just wants a copy of the modified ejb3 cartridge I am using, feel free to ping me.

Step 1 - create a new Andromda project.

From command line>

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

A variety of questions will be asked, below are the options I selected:
Options: 
Rich Client
J2EE
c:/development/andromda_test_portlet
Brad Rideout
UML2
Brad Test Portlet
bradtestportlet
1.0-SNAPSHOT
com.mdahatter.bradportlettest
ear
ejb3
mysql
no
yes
jsf
jsf2
portlet
no
no
Step 2 - modify mda/pom.xml
Since I am using Maven 2.0.9 I had to modify the mda/pom.xml v2.0.8 does not require this step...
find the model.uri section and change it to:

file:${pom.basedir}/src/main/uml/bradportlettest.uml2

Step 3 - Open /mda/src/main/uml/bradportlettest.xml with your uml tool.
I use Magicdraw community version.
The first time you open the project, make sure you set the maven2.repository to your .m2/repository. This can be done in the Options-Environment Options tab.

Step 4 - Create a class diagram
In MagicDraw, right click on the 'Data' folder and click 'New Element--Model', name it 'mdahatter'
Right click on 'mdahatter' and select 'New Element'--'Package' name it com.mdahatter.bradportlettest
Right click on com.mdahatter.bradportlettest and select 'New Diagram'-'class diagram' .. name it 'VOPC'
Add a new class called 'User' with 3 string attributes: 'firstName', lastName', 'email'
Make sure all attributes are public, and use the String [datatype]
Right click on the class and go to the 'Stereotypes' section, select 'Entity' and 'Manageable'... Note: make sure you select the stereotypes from the org.andromda.profile.persistence profile

Step 5 - Export model
Save the model, and select File-Export-EMF UML2 (v1.x) XMI

Step 6 - modify maven pom.xml files

Step 6(A) open the pom.xml in the root of your project.
I modify the org.andromda.cartridge dependency to point to my 1.0-GLASSFISH version of the cartridge. If you are using JBOSS, you should be able to leave this...

org.andromda.cartridges
andromda-ejb3-cartridge
1.0-GLASSFISH
runtime


I also added the Apache maven repository under the area:


apache
Apache Repository
http://people.apache.org/repo/m2-snapshot-repository/


Step 6 (B) Modify the web/pom.xml

In the web/pom.xml find the 'org.apache.myfaces.tomahawk' dependency, and change it like so:


org.apache.myfaces.tomahawk
tomahawk
1.1.7-SNAPSHOT
jar


Step 7 - Run the maven build

From the command line, navigate to the root of the new project and run the command: mvn

**** Right now this creates all of the files, etc. but there is still a bug preventing it from totally compiling for me ****** more once I get that bug fixed!