Search code examples
javamavenosgiaether

Programatically build and launch contained applications based on Maven dependecies


I would like to take several lists of Maven dependencies from the user, resolve and load each of them as contained applications. Here are the steps:

  1. collect a list of all Maven dependencies (DONE)
  2. resolve all dependencies with Aether (DONE)
  3. resolve classpath with Aether (DONE)
  4. bundle the above in a separate "container" (so that different Maven dependencies with potential conflicting version can be used).
  5. repeat with other lists.

To give some context: I want to use the above in the context of UIMA, to be able to run different (natural language processing) pipelines that rely on different sets of libraries with different versions. My goal is to create an annotation-server in which one defines (Maven) dependencies and pipelines that can be called in a RESTful way. The pipelines (and their corresponding dependencies) should each run in a contained classpath environment (so as to avoid classpath clashes).

Is OSGi the way to go? Based on a classpath (:= a list of resolved jar), can I then build an OSGi bundle and deploy it? All programmatically? I do not have control over the maven dependencies (they are UIMA components, that's it), so no way to add OSGi metadata there.


Solution

  • Would maven-assembly-plugin combined with maven profiles take care of this for you?

    You can filter dependencies differently on a per profile basis. You can use profile specific assembly descriptor documents and generate custom manifest to be placed in the war. You are describing a J2EE Web Application (war) assembly -- they will run in a firewalled classloader inside a servlet container so you generate a bunch of them based on the same source (just vary the web app context and the contents of the WEB-INF/lib on a per profile basis.

    Drop them into the same Tomcat server, for example, and you are ready to go. Was this what you meant?

    HTH,

    Nick