AndroMDA, Maven2, Eclipse...

Tips for using AndroMDA for the back-end only, with eclipse as the IDE.

Some links :

J2EE WebApp

Here, we'll use the base "web" project skeleton generated by AndroMDA, and customize it a little bit for using Stripes as the web framework.

AndroMDA

  • Generate the AndroMDA project using JSF (look here)
  • remove the jsf namespace from andromda.xml (in mda/src/main/config)
  • edit the top-level pom and remove jsf dependencies
  • also remove the andromdapp-maven-plugin from the top level pom's pulgins section (this way we won't have a .project in the top-level folder : we'll use this one as a workspace in eclipse)

Web Project

  • remove everything under the web folder
  • recreate a pom in web that simply includes eclipse and cargo stuff (see below)
  • create a webapp folder in the web project (in src/main), and put a WEB-INF and web.xml in there)
  • try it : create a dummy index.jsp in the freshly created webapp folder, build everything (mvn in the top-level folder), cd to the web project and run jetty via cargo (mvn cargo:start)
  • point your browser to http://localhost:8080/ and test the jsp

NOTE
I've encountered problems with cargo : it doesn't find the libs from the pom.xml, and thereby I had ClassNotFoundExceptions everywhere :-/ Thus I dropped the cargo idea even if it was nice, and use Eclipse to launch the app in dev mode.

You can also create the database schema. Refer to this doc for install and config instructions for your database vendor. The command to create the schema is :

 mvn -f core/pom.xml andromdapp:schema -Dtasks=create

Eclipse setup

  • create the eclipse projects (mvn eclipse:eclipse in the top-level project folder) : this DOES NOT create a .project in the top-level folder, but it should have created some in the subfolders, for each module
  • swith workspace to the top-level folder
  • import the projects (in subfolders) into eclipse
  • set the M2_REPO variable to your local m2 repository

NOTE
I've had a problem with a missing jta jar (wasn't in my local repo, but the eclipse plugin defined it in the core's .classpath... Let's see later on if we need that : for the moment, everything compiles and it's cool !

Now, you should be able to implement the business methods in eclipse.

Running unit tests and debugging in eclipse

This allows to check if everything is ok and if you can execute code from eclipse (much faster than switching to maven everytime IMO). Also, debugging is pretty useful sometimes ;-P

Database connection settings

  • comment out the dataSource property in the AndroMDA config (andromda.xml) so that you use the local one
  • check out your DB connection settings (in the local maven profile of the top-level pom)
  • include the dependency on your JDBC driver in the core's pom
  • run mvn on the top-level project (this will download the jar of your driver)
  • add the driver Jar in eclipse (use the M2_REPO variable to get the jar you're specifying in the pom)

Test sources and execution

  • create a folder for the test sources (core/src/test/java), and add it to the eclipse source folders
  • create a JUnit test case in the created folder, and implement testing methods for your service(s)
  • refresh everything into eclipse and try to run your test
  • run mvn in the top-level folder, it should execute your tests as well

Running and debugging the webapp from eclipse

I don't know how to set the path to "WebContent" in eclipse. I've searched for it everywhere but apparently you can't update that. So, maybe, when you'll try to run the project on the server, you won't have access to your JSPs and web.xml will be ignored. I don't know why, but it seems that if you have a WEB-INF folder and a JSP in your "WebContent" folder (which should be web/src/main/webapp), it recognizes the path automatically and things are ok.

TBC