GlassFish has a modular architecture based upon OSGi and bundles Apache Felix as the OSGi runtime. TOTD #103 explains how to run GlassFish with two other OSGi runtimes (Equinox and Knopflerfish). However you may already have an OSGi runtime in your environment and like to run GlassFish within it. Sahoo blogged about how to embed GlassFish in Equinox.
This Tip Of The Day (TOTD) provides complete set of steps with Equinox and the different download options.
- There are two download options for Equinox – SDK or Framework. The framework is an easier option to start with as its just a single JAR. So create a top-level directory as "equinox-3.5.2" and download the latest framework JAR from here. Complete details about the starting and configuring the framework are described here.
- Start the framework and check its status as:
~/tools/equinox-3.5.2 >java -jar org.eclipse.osgi_3.5.2.R35x_v20100126.jar -console osgi> ss Framework is launched. id State Bundle 0 ACTIVE org.eclipse.osgi_3.5.2.R35x_v20100126
Notice only one bundle, i.e. Equinox main bundle, is currently active.
- Download and unzip the latest GlassFish 3.1 nightly build.
- Shutdown the framework by typing "exit" on the console or Ctrl+C. Copy "glassfish/osgi/equinox/configuration/config.ini" to "equinox-3.5.2/configuration" directory. This is required because the version number of some packages exported by JRE is not uniform across frameworks. This will hopefully be fixed in future versions of the frameworks.
- Sahoo’s blog describes an OSGi bundle that controls the lifecycle of GlassFish. Download and unzip the OSGi bundle’s Maven project.
- Edit "src/main/java/sahoo/embeddedgf/GFActivator.java" file and change the value of "installRoot" and "instanceRoot" on line 73 and 74 to match the location of your GlassFish install. Build the bundle as:
mvn package
which generates "target/embeddedgf-1.0-SNAPSHOT.jar". The bundle performs three tasks:
- Install all the bundles from "glassfish/modules" directory.
- Creates a configuration with "com.sun.aas.installRoot" and "com.sun.aas.instanceRoot" properties.
- Starts the main GlassFish bundle.
- Start the framework again, install the bundle, and check its status as:
osgi> install file:///Users/arungupta/samples/v3/osgi/embeddedgf/target/embeddedgf-1.0-SNAPSHOT.jar Bundle id is 1 osgi> ss Framework is launched. id State Bundle 0 ACTIVE org.eclipse.osgi_3.5.2.R35x_v20100126 1 INSTALLED sahoo.embeddedgf_1.0.0.SNAPSHOT
Now GlassFish bundle is installed but not started. Optionally, the framework may be started with "-clean" switch that clears out the cache and starts with a clean slate.
- Start the newly installed bundle and see the log messages as:
osgi> start 1 osgi> [#|2010-04-10T10:46:04.616-0700|INFO|glassfishv3.0|com.sun.grizzly.config.GrizzlyServiceListener|_ThreadID=10;_ThreadName=Configuration Updater;|Perform lazy SSL initialization for the listener 'http-listener-2'|#] [#|2010-04-10T10:46:04.700-0700|INFO|glassfishv3.0|null|_ThreadID=11;_ThreadName=Thread-13;|Grizzly Framework 1.9.19-beta1 started in: 26ms listening on port 4848|#] [#|2010-04-10T10:46:04.700-0700|INFO|glassfishv3.0|null|_ThreadID=12;_ThreadName=Thread-9;|Grizzly Framework 1.9.19-beta1 started in: 50ms listening on port 8181|#] [#|2010-04-10T10:46:04.709-0700|INFO|glassfishv3.0|null|_ThreadID=13;_ThreadName=Thread-8;|Grizzly Framework 1.9.19-beta1 started in: 135ms listening on port 8080|#] . . . [#|2010-04-10T10:46:11.625-0700|INFO|glassfishv3.0|null|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, service.pid=org.apache.felix.fileinstall.76a03b47-814c-4359-ad37-f5d12e752a6f, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/3.1/apr9/glassfishv3/glassfish/domains/domain1/autodeploy/bundles/, felix.fileinstall.filename=org.apache.felix.fileinstall-autodeploy-bundles.cfg, service.factorypid=org.apache.felix.fileinstall, felix.fileinstall.debug=1};|{felix.fileinstall.poll (ms) = 5000, felix.fileinstall.dir = /Users/arungupta/tools/glassfish/3.1/apr9/glassfishv3/glassfish/domains/domain1/autodeploy/bundles, felix.fileinstall.debug = 1, felix.fileinstall.bundles.new.start = true, felix.fileinstall.tmpdir = /var/folders/+E/+E6YtSvGGEKNwOA77I-9Fk+++TI/-Tmp-/fileinstall--1798045578591636699, felix.fileinstall.filter = null}|#]
- Check the status of installed bundle as:
osgi> ss Framework is launched. id State Bundle 0 ACTIVE org.eclipse.osgi_3.5.2.R35x_v20100126 Fragments=89, 106, 109 1 ACTIVE sahoo.embeddedgf_1.0.0.SNAPSHOT 2 RESOLVED org.glassfish.appclient.acc-config_3.1.0.SNAPSHOT 3 RESOLVED org.glassfish.admin.cli_3.1.0.SNAPSHOT 4 RESOLVED org.glassfish.admin.core_3.1.0.SNAPSHOT 5 RESOLVED org.glassfish.admin.util_3.1.0.SNAPSHOT . . . 220 ACTIVE org.glassfish.web.weld-integration_3.1.0.SNAPSHOT 221 RESOLVED org.jboss.weld.osgi-bundle_1.0.1.SP1 222 RESOLVED com.ctc.wstx_0.0.0 223 RESOLVED org.glassfish.connectors.work-management_3.1.0.SNAPSHOT osgi>
So now all the GlassFish modules are installed and the required ones are started. "http://localhost:8080" shows the default web page and "asadmin" can be used to issue the standard commands.
If you downloaded Eclipsed SDK, then the framework needs to be started as:
java -jar plugins/org.eclipse.osgi_3.5.2.R35x_v20100126.jar -console
and the configuration file needs to be copied to "plugins/configuration" directory.
A future blog will show how to run GlassFish inside Eclipse as an RCP, however this requires issue #11782 to be fixed.
There are several other OSGi entries on this blog or on Sahoo’s blog.
How are you using GlassFish’s OSGi capabilities ?
Technorati: totd glassfish osgi embedded eclipse equinox
Related posts:- TOTD #103: GlassFish v3 with different OSGi runtimes – Felix, Equinox, and Knoplerfish
- TOTD #131: Dynamic OSGi services in GlassFish – Using ServiceTracker
- TOTD #125: Creating an OSGi bundles using NetBeans and deploying in GlassFish
- TOTD #140: Moving GlassFish Installation – Referenced file does not exist “osgi-main.jar”
- TOTD #115: GlassFish in Eclipse – Integrated Bundle, Install Stand-alone or Update Existing plugin