AndroMDA, Maven2, Eclipse...
Tips for using AndroMDA for the back-end only, with eclipse as the IDE.
Some links :
- Eclipse, J2EE and M2 : http://www.trajano.net/2006/03/j2ee-with-maven-2-wtp.html
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(inmda/src/main/config) - edit the top-level pom and remove jsf dependencies
- also remove the
andromdapp-maven-pluginfrom the top level pom'spulginssection (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
webfolder - recreate a pom in
webthat simply includes eclipse and cargo stuff (see below) - create a
webappfolder in thewebproject (insrc/main), and put aWEB-INFandweb.xmlin there) - try it : create a dummy
index.jspin the freshly createdwebappfolder, build everything (mvnin the top-level folder), cd to thewebproject 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:eclipsein 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
dataSourceproperty in the AndroMDA config (andromda.xml) so that you use the local one - check out your DB connection settings (in the
localmaven profile of the top-level pom) - include the dependency on your JDBC driver in the
core's pom - run
mvnon the top-level project (this will download the jar of your driver) - add the driver Jar in eclipse (use the
M2_REPOvariable 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
mvnin 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