Skip to main content

Running GlassFish on other OSGi platforms

Posted by ss141213 on May 30, 2009 at 12:05 PM PDT

Although GlassFish v3 Preview comes with Felix pre-installed, it's pretty easy to make it run on Equinox and other platforms. Given below are the simple steps... 1. Download Equinox or if you have it, use that. 2. cp org.eclipse.osgi_3.3.2.R33x_v20080105.jar $GlassFish_HOME/osgi/equinox/ (replace 3.3.2.R33x_v20080105 by the actual version found in jar name in your equinox installation. It changes from version to version.) 3. Start GlassFish, but while starting let it know that you want to run on Equinox, else by default it uses Felix. To do this, you have couple of choices: a) You can set an environment variable called GlassFish_Platform as Equinox. b) You can set a system property called GlassFish_Platform as Equinox. Why do we have these two options? The system property is handy when you are starting using "java -jar" command. The environment variable is useful when you are starting using the classic way, i.e., "asadmin start-domain." Putting them in practice: (I am using Bash shell in the following example) 1. In the following example, we set the option once in the environment and every subsequent use of "asadmin start-domain" starts GlassFish on Equinox.

   export GlassFish_Platform=Equinox
   asadmin start-domain

2. In the example below, asadmin start-domain is used to start GlassFish, but you are able to specify the enviornment variable on the same command.

GlassFish_Platform=Equinox asadmin start-domain

3. If you are used to "java -jar" style of starting GlassFish (a new thing in GlassFish v3), then do this:

java -DGlassFish_Platform=Equinox $GlassFish_HOME/modules/glassfish.jar

Frequently Asked Questions: 1. What is the order of precedence? In our bootstrap code that decides which platform to use, System property takes precedence over environment. So, if you set GlassFish_Platform in both system property and in environment, system property wins. 2. What are the allowable values for GlassFish_Platform? The set of acceptable values are statically defined in an Enum like this: public enum Platform {Felix, Knopflerfish, Equinox, Static} So, you can specify any one of them. The default value is Felix. 3. What platform does "Static" mean in the above Enum? Well, GlassFish can run without OSGi as well. Static refers to that mode. There appears to be some use case for this mode. 4. OK, I see Knopflerfish being mentioned as one of the platforms. How can I run on that? When we started our OSGi effort, we were using only R4 APIs and hence we could run on all three popular, open source OSGi platforms. Later on, we had to rely on some R4 version 4.1 APIs - to be precise, on "transient" start/stop of bundles supported via new API called Bundle.start(int), Bundle.stop(int). Knopflerfish still does not implement them. Last time, when I checked with them, they told that they will switch from R4 to R4.2 directly. So, latest GlassFish v3 (something like GlassFish 3.0-Preview) does not currently run on Knopflerfish. Having said that, GlassFish 3.0-Prelude can run on Knopflerfish. 5. Where do I find configuration file for each platform? Here is where you can locate the configuration files: Felix -> glassfish/osgi/felix/conf/config.properties Equinox -> glassfish/osgi/equinox/configuration/config.ini Knopflerfish -> Not available, as latest GlassFish does not run on it. 6. Must I have my OSGi framework jars copied to GlassFish installation directory? What if I am sharing an installation and don't have permission to change the installation? No, you don't have to copy the OSGi framework jars to glassfish/osgi directory. You can keep them on a separate location and refer to that using environment or system variables. e.g., you can do this: mkdir /usr/equinox cp org.eclipse.osgi_3.3.2.R33x_v20080105.jar /usr/equinox/ cp -r glassfish/osgi/equinox/configuration/ /usr/equinox/ java -DGlassFish_Platform=Equinox -DEQUINOX_HOME=/usr/equinox/ glassfish.jar Of course, you can set those properties using environment variables as well if you don't want to set them every time. 7. While running on Equinox, I get a WARNING like this: WARNING: Failed to install .../glassfish/modules/osgi-main.jar because of org.osgi.framework.BundleException: Bundle "com.sun.enterprise.osgi-main" version "0.3.64" has already been installed from: initial@reference:file:../../modules/osgi-main.jar/ It is coming because our management agent, which goes through modules dir to install all the modules, is trying to install a module called osgi-main.jar, but that module is already configured in config.ini to be autostarted. You can safely ignore the warning. 8. How do I add support for other OSGi platforms? Currently, you have to make some changes in our bootstrap code to achieve this. To be precise: in two files: ASMain.java and a new file that you need to supply. This is because of lack of standard way of starting OSGi frameworks. Work is in progress in OSGi Core Platform Expert Group under RFC #132 to have a uniform API to start a framework. Once it is available as part of OSGi R4.2 platform, we will switch to it and integration with other frameworks will be much smoother. Conclusion Happy GlassFish-ing. As usual, please refer to The Aquarium for more information about GlassFish suite of projects and products. Your feedback is always welcome.

Related Topics >>

Comments

gf 3 final + Equinox = lots of IllegalArgumentException

Hi Sahoo. First, thanks much for this blog entry.

When running glassfish with Equinox 3.6.0, I get many of the following exceptions:
java.lang.IllegalArgumentException: No matching constant for 512
at org.jvnet.hk2.osgiadapter.BundleEventType.valueOf(BundleEventType.java:66)
at org.jvnet.hk2.osgiadapter.HK2Main.bundleChanged(HK2Main.java:168)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:919)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1351)
at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1302)
at org.eclipse.osgi.framework.internal.core.BundleHost.readyToResume(BundleHost.java:440)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:368)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1069)
at org.eclipse.osgi.framework.internal.core.PackageAdminImpl.resumeBundles(PackageAdminImpl.java:302)
at org.eclipse.osgi.framework.internal.core.PackageAdminImpl.processDelta(PackageAdminImpl.java:546)
at org.eclipse.osgi.framework.internal.core.PackageAdminImpl.doResolveBundles(PackageAdminImpl.java:239)
at org.eclipse.osgi.framework.internal.core.PackageAdminImpl.resolveBundles(PackageAdminImpl.java:185)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:318)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:279)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:271)

It seems the version of hk2 is missing the lazy activation bundle event: http://www.osgi.org/javadoc/r4v42/constant-values.html#org.osgi.framewor...

Is there a newer version of hk2 I can load into gf3?

Most things seem to work fine, although occasionally gf wont start with Equinox (something about a bundle being in the wrong state), and I wonder if this is the cause?

Re: gf 3 final + Equinox = lots of IllegalArgumentException

Hi,

You are right. BundleEventType.java in HK2 is missing LAZY_ACTIVATION event type and that will cause an IllegalArgumentException to be thrown by from a synchronous event listener and that will cause a Framework.ERROR to be reported, but things should work as normal. I can't relate that to GFnot starting. The reason GF may not start is because of bundles not resolving perhaps. Do you have Equinox logs? I sincerely suggest you to discuss this in our forum:

http://forums.java.net/jive/forum.jspa?forumID=56&start=0

Thanks,

Sahoo

Launch other Platform - Apache Felix Karaf

Hi Sahoo, As OSGI R4.2 is out. Can you tell us if Glassfish v3 is already compliant with this spec ? IF this is the case, How can add a launcher to work with Apache Felix Karaf ? Regards, Charles

No, GlassFish still does not

No, GlassFish still does not use the new launcher API. Can you file an enhancement request for the same in glassfish issue tracker?