Monday, April 20, 2009

How to set up an eclipse target platform and a run configuration for EasyBeans

This is the first of a series of planned posts on developing EasyBean bundles in an eclipse / equinox environment.


In essance most of what we are trying to accomplish is already explained in Ekke's excellent post. I just have some comments to add:

1) Go for EasyBeans 1.1, even though it may not be GA (RC1 is out as of writing this), especially if you plan to use EasyBeans with some other framework (and who wouldn't?). The logging problem that Ekke describes in this post, seems not to be fixed in the 1.o release, at least I could not get Eclipse RAP and EasyBeans to run together (while Ekke was struggeling with Riena and EasyBeans). In fact, I use bundle org.apache.commons.logging in lieu of the EasyBeans bundle ow2-bundles-externals-commons-logging.

2) Try to understand the EasyBeans startup phases in OSGI, which makes it easier to setup your run configurations in eclipse:
a) First Phase: OSGI is started, some EasyBeans bundles are started, but most EasyBeans bundles are just in state RESOLVED, but not started.
This is what the OSGI console provides after this phase:



osgi> ss

Framework is launched.

id State Bundle
0 ACTIVE org.eclipse.osgi_3.4.0.v20080605-1900
1 RESOLVED org.ow2.easybeans.examples.entitybean_1.1.0.M3
2 RESOLVED org.ow2.easybeans.agent_1.1.0.M3
3 RESOLVED org.ow2.easybeans.component.quartz_1.1.0.M3
4 RESOLVED org.ow2.easybeans.component.joram_1.1.0.M3
5 ACTIVE org.eclipse.osgi.services_3.1.200.v20071203
6 RESOLVED org.ow2.easybeans.component.jmx_1.1.0.M3
7 RESOLVED org.ow2.easybeans.component.jotm_1.1.0.M3
8 RESOLVED org.ow2.easybeans.component.statistic_1.1.0.M3
9 ACTIVE org.ow2.bundles.ow2-util-event-api_1.0.11
10 ACTIVE org.eclipse.equinox.cm_1.0.0.v20080509-1800
11 RESOLVED org.ow2.easybeans.component.jdbcpool_1.1.0.M3
12 RESOLVED org.ow2.easybeans.component.event_1.1.0.M3
13 RESOLVED org.ow2.easybeans.core_1.1.0.M3
14 ACTIVE org.apache.felix.dependencymanager_1.1.0.10
15 ACTIVE slf4j.api_1.5.2
Fragments=24
16 ACTIVE org.ow2.bundles.ow2-bundles-externals-commons-modeler_1.0.11
17 RESOLVED org.ow2.easybeans.component.hsqldb_1.1.0.M3
18 ACTIVE org.eclipse.equinox.ds_1.0.0.v20080427-0830
19 RESOLVED org.ow2.bundles.ow2-util-jmx-impl_1.0.11
20 RESOLVED org.ow2.easybeans.component.carol_1.1.0.M3
21 RESOLVED org.ow2.bundles.ow2-util-event-impl_1.0.11
22 ACTIVE org.ow2.bundles.ow2-util-jmx-api_1.0.11
23 ACTIVE org.apache.commons.logging_1.0.4.v20080605-1930
24 RESOLVED slf4j.jcl_1.5.2
Master=15
25 ACTIVE org.eclipse.equinox.common_3.4.0.v20080421-2006
26 ACTIVE org.eclipse.equinox.util_1.0.0.v20080414

b) Second Phase: The EasyBean agent bundle is started. This is done either manually in the OSGI console (e.g. "start 2" in the above example) or as part of the start configuration with a higher run level. The agent starts all other important EasyBeans bundles.
This is the what the OSGI console provides after this phase:



OSGI> ss

Framework is launched.

id State Bundle
0 ACTIVE org.eclipse.osgi_3.4.0.v20080605-1900
1 RESOLVED org.ow2.easybeans.examples.entitybean_1.1.0.M3
2 ACTIVE org.ow2.easybeans.agent_1.1.0.M3
3 ACTIVE org.ow2.easybeans.component.quartz_1.1.0.M3
4 ACTIVE org.ow2.easybeans.component.joram_1.1.0.M3
5 ACTIVE org.eclipse.osgi.services_3.1.200.v20071203
6 ACTIVE org.ow2.easybeans.component.jmx_1.1.0.M3
7 ACTIVE org.ow2.easybeans.component.jotm_1.1.0.M3
8 ACTIVE org.ow2.easybeans.component.statistic_1.1.0.M3
9 ACTIVE org.ow2.bundles.ow2-util-event-api_1.0.11
10 ACTIVE org.eclipse.equinox.cm_1.0.0.v20080509-1800
11 ACTIVE org.ow2.easybeans.component.jdbcpool_1.1.0.M3
12 ACTIVE org.ow2.easybeans.component.event_1.1.0.M3
13 ACTIVE org.ow2.easybeans.core_1.1.0.M3
14 ACTIVE org.apache.felix.dependencymanager_1.1.0.10
15 ACTIVE slf4j.api_1.5.2
Fragments=24
16 ACTIVE org.ow2.bundles.ow2-bundles-externals-commons-modeler_1.0.11
17 ACTIVE org.ow2.easybeans.component.hsqldb_1.1.0.M3
18 ACTIVE org.eclipse.equinox.ds_1.0.0.v20080427-0830
19 ACTIVE org.ow2.bundles.ow2-util-jmx-impl_1.0.11
20 ACTIVE org.ow2.easybeans.component.carol_1.1.0.M3
21 ACTIVE org.ow2.bundles.ow2-util-event-impl_1.0.11
22 ACTIVE org.ow2.bundles.ow2-util-jmx-api_1.0.11
23 ACTIVE org.apache.commons.logging_1.0.4.v20080605-1930
24 RESOLVED slf4j.jcl_1.5.2
Master=15
25 ACTIVE org.eclipse.equinox.common_3.4.0.v20080421-2006
26 ACTIVE org.eclipse.equinox.util_1.0.0.v20080414

c) Third Phase: The actual bean bundles, for instance one of the delivered example bundles such as org.ow2.easybeans.examples.entitybean, are started. Now here is the problem: The agent from the previous phase starts all the other EasyBeans bundles and it does it slowly and outside of the Equinox startup procedure. This means you CANNOT start the bean bundle as part of the run configuration by giving it even a higher run level than the agent bundle! This is tricky, because if you tried it anyway the console would still say that all bundles are ACTIVE, leading you to believe that your bean bundle is really deployed with EasyBeans, but it's not. You have to start these bundles manually or through a deployer bundle (which would be good topic for another post). So, to stay with example from phase 2, I start the entity bean bundle org.ow2.easybeans.examples.entitybean by typing "start 1" in the OSGI console.

3) Ekke's example my be a little outdated in terms of what bundles need to be started. So I just give my runtime configuration. In the run configuration, bundles tab, I got the following entries (format "bundle name" + "@" + start level + ":" + auto-start):
org.ow2.easybeans.agent@5:true
org.ow2.easybeans.component.quartz@default:false
org.eclipse.osgi.services@default:true
org.ow2.easybeans.component.jmx@default:false
org.ow2.easybeans.component.event@default:false
org.ow2.bundles.ow2-bundles-externals-commons-modeler@default:true
org.eclipse.equinox.ds@default:true
org.ow2.bundles.ow2-util-jmx-impl@default:default
org.ow2.easybeans.component.carol@default:false
org.ow2.bundles.ow2-util-event-impl@default:default
org.ow2.easybeans.examples.entitybean@default:false
org.ow2.easybeans.component.joram@default:false
org.ow2.easybeans.component.jotm@default:false
org.ow2.easybeans.component.statistic@default:false
org.eclipse.osgi@:
org.ow2.bundles.ow2-util-event-api@default:default
org.eclipse.equinox.cm@default:true
org.ow2.easybeans.component.jdbcpool@default:false
org.ow2.easybeans.core@default:true
org.apache.felix.dependencymanager@default:default
slf4j.api@default:true
org.ow2.easybeans.component.hsqldb@default:false
org.ow2.bundles.ow2-util-jmx-api@default:default
org.apache.commons.logging@default:default
slf4j.jcl@default:false
org.eclipse.equinox.common@default:default
org.eclipse.equinox.util@default:true

In my run configuration, arguments tab, I got the following VM arguments:
-Dorg.osgi.service.http.port=11112 -Dosgi.noShutdown=true

-Declipse.ignoreApp=true
-Dorg.osgi.framework.system.packages=org.osgi.framework;



version=1.3.0,javax.accessibility;javax.activity;javax.imageio;javax.imageio.event;


javax.imageio.metadata;javax.imageio.plugins.bmp;javax.imageio.plugins.jpeg;


javax.imageio.spi;javax.imageio.stream;javax.management;javax.management.loading;


javax.management.modelmbean;javax.management.monitor;javax.management.openmbean;


javax.management.relation;javax.management.remote;javax.management.remote.rmi;


javax.management.timer;javax.naming;javax.naming.directory;javax.naming.event;


javax.naming.ldap;javax.naming.spi;javax.net;javax.net.ssl;javax.print;


javax.print.attribute;javax.print.attribute.standard;javax.print.event;


javax.rmi;javax.rmi.CORBA;javax.rmi.ssl;javax.security.auth;javax.security.cert;


javax.security.auth.callback;javax.security.auth.kerberos;javax.security.auth.login;


javax.security.auth.spi;javax.security.auth.x500;javax.security.sasl;javax.sound.midi;


javax.sound.midi.spi;javax.sound.sampled;javax.sound.sampled.spi;javax.sql;javax.sql.rowset;


javax.sql.rowset.serial;javax.sql.rowset.spi;javax.swing;javax.swing.border;


javax.swing.colorchooser;javax.swing.event;javax.swing.filechooser;javax.swing.plaf;


javax.swing.plaf.basic;javax.swing.plaf.metal;javax.swing.plaf.multi;javax.swing.plaf.synth;


javax.swing.table;javax.swing.text;javax.swing.text.html;javax.swing.text.html.parser;


javax.swing.text.rtf;javax.swing.tree;javax.swing.undo;javax.xml;javax.xml.datatype;


javax.xml.namespace;javax.xml.parsers;javax.xml.transform;javax.xml.transform.dom;


javax.xml.transform.sax;javax.xml.transform.stream;javax.xml.validation;


javax.xml.xpath;org.ietf.jgss;org.omg.CORBA;org.omg.CORBA_2_3;


org.omg.CORBA_2_3.portable;org.omg.CORBA.DynAnyPackage;org.omg.CORBA.ORBPackage;


org.omg.CORBA.portable;org.omg.CORBA.TypeCodePackage;org.omg.CosNaming;


org.omg.CosNaming.NamingContextExtPackage;org.omg.CosNaming.NamingContextPackage;


org.omg.Dynamic;org.omg.DynamicAny;org.omg.DynamicAny.DynAnyFactoryPackage;


org.omg.DynamicAny.DynAnyPackage;org.omg.IOP;org.omg.IOP.CodecFactoryPackage;


org.omg.IOP.CodecPackage;org.omg.Messaging;org.omg.PortableInterceptor;


org.omg.PortableInterceptor.ORBInitInfoPackage;org.omg.PortableServer;


org.omg.PortableServer.CurrentPackage;org.omg.PortableServer.POAManagerPackage;


org.omg.PortableServer.POAPackage;org.omg.PortableServer.portable;


org.omg.PortableServer.ServantLocatorPackage;org.omg.SendingContext;


org.omg.stub.java.rmi;org.omg.stub.javax.management.remote.rmi;


org.w3c.dom;org.w3c.dom.bootstrap;org.w3c.dom.css;org.w3c.dom.events;


org.w3c.dom.html;org.w3c.dom.ls;org.w3c.dom.ranges;org.w3c.dom.stylesheets;


org.w3c.dom.traversal;org.w3c.dom.views;org.xml.sax;org.xml.sax.ext;


org.xml.sax.helpers;sun.rmi.server;sun.rmi.transport;sun.rmi.registry;version=1.5.0 -Dorg.osgi.framework.bootdelegation=sun.*,com.sun.*