Sunday, February 5, 2012

Git, Eclipse and Maven multi-module project

More adventures in maven (sometimes I wonder how worth it is with maven), git and Eclipse...

So I have a multi-module maven project I'm working on, something of prototype to use for future reference for Maven managed EAR projects, and I'm using git for version control. I'm used to using SVN in Eclipse (via Subclipse) and CVS of course, unfortunately, but git's a little different. After some experimentation I think I've got things setup so that

A) the parent and each of the sub projects are connected to the same working git repo within Eclipse and
B) the Eclipse project settings are all managed by maven & the m2e plugins so that none of the Eclipse files (or dependency jars! ;) are checked into source control.

No real need there on that second point, just a preference since maven is so uber magically cool (</sarcasm>) and it handles all the gnarlly Eclipse project set up for you. If you like using other editors, this way you don't have all the Eclipse trash to deal with when you check the project out. Plus I like to hurt myself sometimes proving maven can do it a couple of times a year. Usually after a weekend, like this one, I have things worked out and it is actually pretty cool.
So when it comes to version control, to get everything set up and working using git I am doing the following:

  • Clone the project into my active workspace, either by command line or via the Eclipse egit wizards.
  • Import the existing maven projects into my workspace
  • Connect each of the imported projects to the git repo I'm working out it by right clicking on the project and choosing Team > Share Project > selecting Git then finally checking the "Use or create repository in the parent folder" check box. This can be done in bulk by selecting multiple projects

  • Now I have my nice snazzy maven/m2e managed multi-module project and all the flexible goodnes that comes with it, at least twice as much as needed to hang my self multiple times a day for a year, connected to git so I can check things in locally and forget to push the changes up to the bare repo I cloned from ; ) Good times.

    WAS command line to install an .ear

    This is a one liner that I just got to work which installs an .ear containing a single .war into my local copy of WAS8. It's only one example of how one could use the wsadmin command line tool to perform automated installations in WAS. Obviously different types of apps and configurations will require different command lines but this should get an interested person headed down the right road:

    ~/development/tools/IBM/WebSphere/AppServer/bin/wsadmin.sh -username admin -password admin -c '$AdminApp uninstall MavenTutEAR' -c '$AdminApp install MavenTutEAR-1.0.ear { -defaultbinding.virtual.host default_host -usedefaultbindings}' -c '$AdminConfig save' -c 'set appManager [$AdminControl queryNames type=ApplicationManager,*]' -c '$AdminControl invoke $appManager startApplication MavenTutEAR'

    Note that this is hardly the only, or the best way to do something like this. It is just A way to achieve what I was trying to do. Another option I was about to explore is trying out the auto deploy directory setup (Applications > Global deployment settings).

    If your actually curious why I'm doing this (much less posting about it) I have been trying to conquer my fear/ignorance of using maven with WebSphere, EAR's and possibly some EJBs... naa fuck that for now... by building a collection of maven projects that spit out an EAR that I can deploy into WAS. This monster command line is the finishing touch on that adventure.

    It's certainly not good for anything beyond local development, perhaps, but that's all I need right now. If I'm lucky, and the planets align, this same EAR project could be deployed into WebLogic or JBoss too with out much extra fuss.

    Anywho, many thanks to whomever put this page together:
    http://code.google.com/p/codesnippetssite/wiki/BasicWebSphereAdminwsadmin, it was a big help!