Working with Maven and SpringSource dm Server

March 8th, 2009

Since I am a big Maven fan one of the things that pained me when starting to work with the dm Server was that the tooling for managing project dependencies was all based around Eclipse.  The STS 2.0 RC discussed by Christian Dupuis here now has support for a separate test classpath using a proprietary TEST.MF.  To me this still poses a problem when you start thinking about Continous Integration testing.  Currently there is going to be duplication and you will need to keep the classpath understood by your build system and your IDE in synch manually. It is however surprisingly easy to setup Maven and dm Server to play nice, so before posting the code for my recent Spring Integration with dm Server demo from the UK Spring User Group I thought I would walk through setting up dm Server with Maven.

The first thing you need to decide is where you are going to have your shared repository which will be populated by Maven and used by dm Server to resolve dependencies.  You can configure dm Server to use the default Maven repository under your home directory, however for reasons of clarity I prefer to maintain  a separate repository.  So, assuming you have downloaded dm Server and unzipped it, the first thing you will need to do is modify the provisioning configuration in DM_SERVER/config/server.config. By default there is no section for provisioning here with convention being used, so after the osgiConsole section define a section as below.

"osgiConsole": {
    "enabled": true,
    "port": 2401
},
"provisioning" : {
    "searchPaths": [
        "repository/bundles/subsystems/{name}/{bundle}.jar",
        "repository/bundles/ext/{bundle}",
        "${user.home}/servers/dm-server-maven-repo/**/{bundle}.jar",
        "repository/libraries/ext/{library}",
        "repository/libraries/usr/{library}"
    ]
}
}

To test this we will create a simple project which uses Apache Commons lang StrSubstitor class to print the simple message given as an example in the Javadoc for commons lang “You are running with java.version = ${java.version} and os.name = ${os.name}.”)

To create the sample Maven project we can use the Maven archetype plugin so go to the command prompt in the directory where you want to create the test project.

  1. At the command prompt “mvn archetype:generate”
  2. Then select the number relating to maven-archetype-quickstart , 15 by default but may vary according to your setup
  3. Enter a groupId “org.jpartner” in my case
  4. Enter an artifactId “mavenDmHello”
  5. Hit enter to accept the default version “1.0-SNAPSHOT”
  6. For package I used the same value as groupId so “org.jpartner” in my case

Ok, so now we need to open up the pom.xml that has been created for use by the archetype plugin, so change directory to mavenDmHello and open pom.xml in your preferred text editor. After the URL element and before the dependency element add in the below xml fragment to allow Maven to resolve dependencies from the SpringSource Enterprise Bundle Repository, which you can browse here http://www.springsource.com/repository.

Read the rest of this entry »

Filed under: Maven, Spring | No Comments »