Thursday, January 22, 2009

Spring Server + Maven + Eclipse notes

I feel I am a bit more experienced than when I've started.
Last time I've mentioned about problems I've faced. Maybe it's high time to elaborate a bit about solutions.


  1. Tools:


  2. Dependencies management:
    There are two aspect to discus. Firstly that we are usually manage our dependencies using Maven (of course if we are using maven ;D ). Secondly, bundle dependencies management. Using default configuration we need to feed maven repository using maven and spring server repository using Eclipse Server Editor, which in current version seems to be not working, or provisioning mechanisms.
    This bi-declaration effect have also consequences in how it is seen by Eclipse.
    We have two declaration of the same library in build path.


    As I am using multi-module project. And have inter-module dependencies it resulted in build path error and compilation failure.


    Default configuration has also other consequence. We have to double dependencies definition or we have maven script not usable outside Eclipse tooling. What if we want to share the project? We need to toss the usr bundle catalog round the users, etc.

  3. Solutions:
      Server configuration

      Fortunately we can make our server to use maven repository structure to look for bundles. What I am using is slightly modified configuration from documentation. As OSGi enabled bundles from spring are usually
      in com.springsourceXXX packages we can reuse this information:

      "searchPaths": [
      "repository/bundles/subsystems/{name}/{bundle}.jar",
      "repository/bundles/ext/{bundle}",
      "${user.home}/.m2/repository/**/com.springsource*/**/{bundle}.jar",
      "repository/libraries/ext/{library}",
      "repository/libraries/usr/{library}"
      ]


    • Repository configuration


      Second observation is:use OSGi enabled libraries. In other case you will need to deal with inner JAR's. Which add to the management complexity IMHO.
      Most common libraries prepared to work in OSGi can be found in SpringSource maven repository:

      <repositories>
      <repository>
      <id>com.springsource.repository.bundles.release</id>
      <name>SpringSource Enterprise Bundle Repository -
      SpringSource Bundle Releases</name>
      <url>http://repository.springsource.com/maven/bundles/release</url>
      <releases>
      <updatePolicy>daily</updatePolicy>
      <checksumPolicy>ignore</checksumPolicy>
      </releases>
      </repository>
      <repository>
      <id>com.springsource.repository.bundles.external</id>
      <name>SpringSource Enterprise Bundle Repository -
      External Bundle Releases</name>
      <url>http://repository.springsource.com/maven/bundles/external</url>
      </repository>
      </repositories>

      How to find correct dependency? Easly :) SpringServer editor can lead you to repository browser (Look at the picture).

    • Independ maven build

      The last step to is to keep all dependencies in maven. Why ? Independent build.
      My solution is maybe naive but it works - Maven profiles.


      <profiles>
      <profile>
      <id>standalone</id>
      <dependencies>
      <dependency>
      <groupId>com.oracle.jdbc</groupId>
      <artifactId>com.springsource.oracle.jdbc</artifactId>
      </dependency>
      <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>com.springsource.org.apache.commons.collections</artifactId>
      <version>3.2.0</version>
      <scope>provided</scope>
      </dependency>
      <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>org.springframework.web.servlet</artifactId>
      <version>${spring.components.version}</version>
      <scope>provided</scope>
      </dependency>
      </dependencies>
      </profile>
      </profiles>


      To build project outside the only think you need to do is to eneble standalone profile.



2 comments:

milus said...

Hi

I have a couple of questions.
I would like to know how do you manage dependency on build path level?
Do you use "Bundle Dependencies" Library (com.springsource.server.ide.jdt.core.MANIFEST_CLASSPATH_CONTAINER)
dependencies for that? Or use some maven plugin?

Bartek Michalik said...

I'm using Bundle Dependencies at the Eclipse level. To overcome problem with the doubled dependencies (from Maven) I use profile (disabled) to hide them on Eclipse build path.