Spring Dynamic Modules for OSGi(tm)

The following scripts use Pax-Construct to build and provision a minimal Spring Dynamic Modules for OSGi(tm) project using the 1.1.0-m2 milestone release. It includes an example OSGi enabled Spring bean, created using pax-create-bundle.

This setup requires a Java5 runtime. Some advanced features of Spring Dynamic Modules may require additional bundles to be imported, or extra third-party libraries wrapped.

Download UNIX shell script

Download Windows batch file

Using the scripts:

If you have the Pax-Construct scripts installed and on your path, all you need to do is go to a temporary/working directory and run the script - it will create a new Maven project, populate it with various bundles and deploy them on the Felix OSGi framework. You can deploy to other frameworks by using -Dframework=name

Create Eclipse project files for the various imported, wrapped and compiled bundles:

cd spring

mvn clean install pax:eclipse -DdownloadSources

Use "Import... Existing Projects into Workspace" and point it to the top-most directory to import the bundle projects into your Eclipse Workspace.

Example output when provisioning (assumes 'mvn clean install' has already been run)

cd spring

mvn pax:provision

[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO]   examples.spring (OSGi project)
[INFO]   spring - plugin configuration
[INFO]   spring - wrapper instructions
[INFO]   spring - bundle instructions
[INFO]   spring - imported bundles
[INFO]   asm 2.2.3 [osgi]
[INFO]   aopalliance 1.0 [osgi]
[INFO]   javax.servlet.jsp-api 2.0 [osgi]
[INFO]   javax.servlet.api 2.5 [osgi]
[INFO]   backport-util-concurrent 3.0 [osgi]
[INFO]
[INFO]   org.example.service
[INFO]   org.example.bean
[INFO] Searching repository for plugin with prefix: 'pax'.
[INFO] ------------------------------------------------------------------------
[INFO] Building examples.spring (OSGi project)
[INFO]    task-segment: [pax:provision] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [pax:provision]
[INFO] Installing T:\cygwin\home\stuart\temp\spring\runner\deploy-pom.xml to C:\Users\stuart\.m2\repository\examples\spr
ing\build\deployment\1.0-SNAPSHOT\deployment-1.0-SNAPSHOT.pom
    ______  ________  __  __
   / __  / /  __   / / / / /
  /  ___/ /  __   / _\ \ _/
 /  /    /  / /  / / _\ \
/__/    /__/ /__/ /_/ /_/

Pax Runner from OPS4J - http://www.ops4j.org
--------------------------------------------

 -> Using config [classpath:META-INF/runner.properties]
 -> Provision from [T:\cygwin\home\stuart\temp\spring\runner\deploy-pom.xml]
 -> Provision from [scan-pom:file:/T:/cygwin/home/stuart/temp/spring/runner/deploy-pom.xml]
 -> Using property [org.osgi.service.http.port=8080]
 -> Using property [org.osgi.service.http.port.secure=8443]
 -> Installing bundle [{location=mvn:org.springframework.osgi/spring-osgi-extender/1.1.0-m2,startlevel=null,shouldStart=
true,shouldUpdate=false}]
 -> Installing bundle [{location=mvn:org.slf4j/jcl104-over-slf4j/1.4.3,startlevel=null,shouldStart=true,shouldUpdate=fal
se}]
 -> Installing bundle [{location=mvn:org.slf4j/slf4j-api/1.4.3,startlevel=null,shouldStart=true,shouldUpdate=false}]
 -> Installing bundle [{location=mvn:org.springframework.osgi/spring-osgi-core/1.1.0-m2,startlevel=null,shouldStart=true
,shouldUpdate=false}]
 -> Installing bundle [{location=mvn:org.springframework.osgi/spring-osgi-io/1.1.0-m2,startlevel=null,shouldStart=true,s
houldUpdate=false}]
 -> Installing bundle [{location=mvn:org.springframework/spring-aop/2.5.4,startlevel=null,shouldStart=true,shouldUpdate=
false}]
 -> Installing bundle [{location=mvn:org.springframework/spring-beans/2.5.4,startlevel=null,shouldStart=true,shouldUpdat
e=false}]
 -> Installing bundle [{location=mvn:org.springframework/spring-context/2.5.4,startlevel=null,shouldStart=true,shouldUpd
ate=false}]
 -> Installing bundle [{location=mvn:org.springframework/spring-core/2.5.4,startlevel=null,shouldStart=true,shouldUpdate
=false}]
 -> Installing bundle [{location=mvn:org.springframework/spring-test/2.5.4,startlevel=null,shouldStart=true,shouldUpdate
=false}]
 -> Installing bundle [{location=mvn:org.slf4j/slf4j-simple/1.4.3,startlevel=null,shouldStart=true,shouldUpdate=false}]
 -> Installing bundle [{location=mvn:examples.spring.wrappers/asm/2.2.3-001-SNAPSHOT,startlevel=null,shouldStart=true,sh
ouldUpdate=false}]
 -> Installing bundle [{location=mvn:examples.spring.wrappers/aopalliance/1.0-001-SNAPSHOT,startlevel=null,shouldStart=t
rue,shouldUpdate=false}]
 -> Installing bundle [{location=mvn:examples.spring.wrappers/javax.servlet.jsp-api/2.0-001-SNAPSHOT,startlevel=null,sho
uldStart=true,shouldUpdate=false}]
 -> Installing bundle [{location=mvn:examples.spring.wrappers/javax.servlet.api/2.5-001-SNAPSHOT,startlevel=null,shouldS
tart=true,shouldUpdate=false}]
 -> Installing bundle [{location=mvn:examples.spring.wrappers/backport-util-concurrent/3.0-001-SNAPSHOT,startlevel=null,
shouldStart=true,shouldUpdate=false}]
 -> Installing bundle [{location=mvn:examples.spring/org.example.service/1.0-SNAPSHOT,startlevel=null,shouldStart=true,s
houldUpdate=false}]
 -> Installing bundle [{location=mvn:examples.spring/org.example.bean/1.0-SNAPSHOT,startlevel=null,shouldStart=true,shou
ldUpdate=false}]
 -> Downloading bundles...
 -> mvn:org.springframework.osgi/spring-osgi-extender/1.1.0-m2 : 79012 bytes @ [ 2079kBps ]
 -> mvn:org.slf4j/jcl104-over-slf4j/1.4.3 : 15435 bytes @ [ 2572kBps ]
 -> mvn:org.slf4j/slf4j-api/1.4.3 : 15345 bytes @ [ 3069kBps ]
 -> mvn:org.springframework.osgi/spring-osgi-core/1.1.0-m2 : 270003 bytes @ [ 1646kBps ]
 -> mvn:org.springframework.osgi/spring-osgi-io/1.1.0-m2 : 29512 bytes @ [ 1736kBps ]
 -> mvn:org.springframework/spring-aop/2.5.4 : 326030 bytes @ [ 1964kBps ]
 -> mvn:org.springframework/spring-beans/2.5.4 : 484045 bytes @ [ 2059kBps ]
 -> mvn:org.springframework/spring-context/2.5.4 : 469327 bytes @ [ 2224kBps ]
 -> mvn:org.springframework/spring-core/2.5.4 : 285906 bytes @ [ 3529kBps ]
 -> mvn:org.springframework/spring-test/2.5.4 : 180098 bytes @ [ 3274kBps ]
 -> mvn:org.slf4j/slf4j-simple/1.4.3 : 7449 bytes @ [ 3724kBps ]
 -> mvn:examples.spring.wrappers/asm/2.2.3-001-SNAPSHOT : 37514 bytes @ [ 2679kBps ]
 -> mvn:examples.spring.wrappers/aopalliance/1.0-001-SNAPSHOT : 6366 bytes @ [ 2122kBps ]
 -> mvn:examples.spring.wrappers/javax.servlet.jsp-api/2.0-001-SNAPSHOT : 53207 bytes @ [ 2533kBps ]
 -> mvn:examples.spring.wrappers/javax.servlet.api/2.5-001-SNAPSHOT : 107956 bytes @ [ 2633kBps ]
 -> mvn:examples.spring.wrappers/backport-util-concurrent/3.0-001-SNAPSHOT : 333917 bytes @ [ 3210kBps ]
 -> mvn:examples.spring/org.example.service/1.0-SNAPSHOT : 5178 bytes @ [ 2589kBps ]
 -> mvn:examples.spring/org.example.bean/1.0-SNAPSHOT : 4764 bytes @ [ 2382kBps ]
 -> Execution environment [J2SE-1.5]
 -> Starting platform [Felix 1.0.3]. Runner has successfully finished his job!

Welcome to Felix.
=================

-> 69 [FelixStartLevel] INFO org.springframework.osgi.extender.internal.activator.ContextLoaderListener - Starting [org.
springframework.bundle.osgi.extender] bundle v.[1.1.0.m2]
205 [FelixStartLevel] INFO org.springframework.osgi.extender.internal.support.ExtenderConfiguration - No custom configur
ation detected; using defaults
224 [FelixStartLevel] INFO org.springframework.osgi.extender.internal.activator.ContextLoaderListener - Disabled automat
ic Spring-DM annotation processing; [ org.springframework.osgi.extender.annotation.auto.processing=null]
STARTING org.example.service
REGISTER org.example.service.ExampleService
539 [SpringOsgiExtenderThread-1] INFO org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext - Refresh
ing org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext@9cb0f4: display name [OsgiBundleXmlApplicat
ionContext(bundle=org.example.bean, config=osgibundle:/META-INF/spring/*.xml)]; startup date [Wed Apr 30 09:59:23 SGT 20
08]; root of context hierarchy
774 [SpringOsgiExtenderThread-1] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean d
efinitions from URL [bundle://18.0:0/META-INF/spring/bundle-context-osgi.xml]
1119 [SpringOsgiExtenderThread-1] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean
definitions from URL [bundle://18.0:0/META-INF/spring/bundle-context.xml]
1240 [SpringOsgiExtenderThread-1] INFO org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext - Bean f
actory for application context [org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext@9cb0f4]: org.sp
ringframework.beans.factory.support.DefaultListableBeanFactory@1c4f0f8
1288 [SpringOsgiExtenderThread-1] INFO org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterA
pplicationContextExecutor - No outstanding OSGi service dependencies, completing initialization for OsgiBundleXmlApplica
tionContext(bundle=org.example.bean, config=osgibundle:/META-INF/spring/*.xml)
1295 [SpringOsgiExtenderThread-2] INFO org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instan
tiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1c4f0f8: defining beans [myEx
ampleBean]; root of factory hierarchy
1359 [SpringOsgiExtenderThread-2] INFO org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext - Publis
hing application context as OSGi service with properties {org.springframework.context.service.name=org.example.bean, Bun
dle-SymbolicName=org.example.bean, Bundle-Version=1.0.0.SNAPSHOT}

-> ps

START LEVEL 6
   ID   State         Level  Name
[   0] [Active     ] [    0] System Bundle (1.0.3)
[   1] [Active     ] [    5] spring-osgi-extender (1.1.0.m2)
[   2] [Active     ] [    5] jcl104-over-slf4j (1.4.3)
[   3] [Active     ] [    5] slf4j-api (1.4.3)
[   4] [Active     ] [    5] spring-osgi-core (1.1.0.m2)
[   5] [Active     ] [    5] spring-osgi-io (1.1.0.m2)
[   6] [Active     ] [    5] spring-aop (2.5.4)
[   7] [Active     ] [    5] spring-beans (2.5.4)
[   8] [Active     ] [    5] spring-context (2.5.4)
[   9] [Active     ] [    5] spring-core (2.5.4)
[  10] [Active     ] [    5] spring-test (2.5.4)
[  11] [Active     ] [    5] slf4j-simple (1.4.3)
[  12] [Active     ] [    5] asm 2.2.3 [osgi] (2.2.3)
[  13] [Active     ] [    5] aopalliance 1.0 [osgi] (1.0)
[  14] [Active     ] [    5] javax.servlet.jsp-api 2.0 [osgi] (2.0)
[  15] [Active     ] [    5] javax.servlet.api 2.5 [osgi] (2.5)
[  16] [Active     ] [    5] backport-util-concurrent 3.0 [osgi] (3.0)
[  17] [Active     ] [    5] org.example.service (1.0.0.SNAPSHOT)
[  18] [Active     ] [    5] org.example.bean (1.0.0.SNAPSHOT)
[  19] [Active     ] [    1] osgi.compendium (4.0.1)
[  20] [Active     ] [    1] Apache Felix Shell Service (1.0.0)
[  21] [Active     ] [    1] Apache Felix Shell TUI (1.0.0)

-> services

System Bundle (0) provides:
---------------------------
org.osgi.service.startlevel.StartLevel
org.osgi.service.packageadmin.PackageAdmin

spring-osgi-extender (1) provides:
----------------------------------
org.springframework.beans.factory.xml.NamespaceHandlerResolver
org.xml.sax.EntityResolver

org.example.service (17) provides:
----------------------------------
org.example.service.ExampleService

org.example.bean (18) provides:
-------------------------------
org.springframework.osgi.context.DelegatedExecutionOsgiBundleApplicationContext, org.springframework.osgi.context.Config
urableOsgiBundleApplicationContext, org.springframework.context.ConfigurableApplicationContext, org.springframework.cont
ext.ApplicationContext, org.springframework.context.Lifecycle, org.springframework.beans.factory.ListableBeanFactory, or
g.springframework.beans.factory.HierarchicalBeanFactory, org.springframework.context.MessageSource, org.springframework.
context.ApplicationEventPublisher, org.springframework.core.io.support.ResourcePatternResolver, org.springframework.bean
s.factory.BeanFactory, org.springframework.core.io.ResourceLoader, org.springframework.beans.factory.DisposableBean

Apache Felix Shell Service (20) provides:
-----------------------------------------
org.apache.felix.shell.ShellService, org.ungoverned.osgi.service.shell.ShellService

-> stop 0

36266 [Felix Shell TUI] INFO org.springframework.osgi.extender.internal.activator.ContextLoaderListener - Stopping [org.
springframework.bundle.osgi.extender] bundle v.[1.1.0.m2]
36276 [Thread-1] INFO org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext - Application Context ser
vice already unpublished
36276 [Thread-1] INFO org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext - Closing org.springframe
work.osgi.context.support.OsgiBundleXmlApplicationContext@9cb0f4: display name [OsgiBundleXmlApplicationContext(bundle=o
rg.example.bean, config=osgibundle:/META-INF/spring/*.xml)]; startup date [Wed Apr 30 09:59:23 SGT 2008]; root of contex
t hierarchy
-> 36281 [Thread-1] INFO org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in
 org.springframework.beans.factory.support.DefaultListableBeanFactory@1c4f0f8: defining beans [myExampleBean]; root of f
actory hierarchy
STOPPING org.example.service
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 49 seconds
[INFO] Finished at: Wed Apr 30 09:59:59 SGT 2008
[INFO] Final Memory: 8M/17M
[INFO] ------------------------------------------------------------------------