blob: e2736ebe7e7574533b060292715c9cf51aa28e51 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<!-- $PAGETITLE -->
<TITLE>OpenEJB - OSGi & OpenEJB</TITLE>
<LINK href="http://openejb.apache.org/all.css" rel="stylesheet" type="text/css">
<!--[if IE]><link rel="stylesheet" type="text/css" media="screen, projection" href="openejb.apache.org/ie.css"><![endif]-->
<LINK rel="SHORTCUT ICON" href="http://openejb.apache.org/images/favicon.ico">
<META http-equiv="Content-Type" content="text/html;charset=UTF-8">
<SCRIPT language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></SCRIPT>
<SCRIPT language="javascript" src="http://openejb.apache.org/tweet/jquery.tweet.js" type="text/javascript"></SCRIPT>
<SCRIPT type="text/javascript">
$(document).ready(function(){
$(".tweet").tweet({
avatar_size: 32,
count: 4,
fetch:25,
username: "openejb",
list: "contributors",
template:"{avatar}{text}",
filter: function(t){ return /openejb/i.test(t["tweet_raw_text"]); },
loading_text: "loading list..."
});
});
</SCRIPT>
</HEAD>
<BODY>
<!-- Delay the loading of the external javascript file needed for labels (as it takes too long to load and visibly holds loading of the page body) -->
<!-- To do this without javascript errors over undefined functions, we need to declare stubs here (that are overrided later by the proper implementations) -->
<SCRIPT language="JavaScript" type="text/javascript">
function doAddLabel(hideTextfieldAfterAddParam)
{
// stub
}
function onAddLabel()
{
// stub
}
function showLabelsInput()
{
// stub
}
</SCRIPT>
<A name="top"></A>
<TABLE class="frameTable" cellpadding="0" cellspacing="0" border="0">
<TR class="Row1">
<TD class="Col1"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col2"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col3"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
</TR>
<TR class="Row2">
<TD class="Col1"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3" id="breadcrumbs">
<!-- $TOP_NAV_BAR -->
<A href="index.html" title="Index">Home</A> | <A href="news.html" title="News">News</A> | <A href="faq.html" title="FAQ">FAQ</A> | <A href="download.html" title="Download">Download</A> | <A href="mailing-lists.html" title="Mailing Lists">Lists</A> | <A href="http://issues.apache.org/jira/browse/OPENEJB" class="external-link" rel="nofollow">Issues</A>
</TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">&nbsp;</TD>
</TR>
<TR class="Row3">
<TD class="Col1"><IMG alt="" class="Row3Img" id="thinLine" src="http://openejb.apache.org/images/line_sm.gif"></TD>
<TD class="Col2"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col3"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
</TR>
<TR class="Row4">
<TD class="Col1">
<SPAN id="Navigation">
<H3><A name="Navigation-Overview"></A>Overview</H3>
<UL class="alternate" type="square">
<LI><A href="index.html" title="Index">Home</A></LI>
<LI><A href="news.html" title="News">News</A></LI>
<LI><A href="faq.html" title="FAQ">FAQ</A></LI>
<LI><A href="download.html" title="Download">Download</A></LI>
<LI><A href="../OPENEJBx30/index.html" title="Index">Documentation</A></LI>
<LI><A href="examples.html" title="Examples">Examples</A></LI>
<LI><A href="http://cwiki.apache.org/confluence/display/OPENEJB/Lightening%20Demos" class="external-link" rel="nofollow">Lightning Demos</A></LI>
<LI><A href="mailing-lists.html" title="Mailing Lists">Mailing Lists</A></LI>
<LI><A href="source-code.html" title="Source Code">Source Code</A></LI>
<LI><A href="http://blogs.apache.org/openejb" class="external-link" rel="nofollow">Project Blog</A></LI>
</UL>
<H3><A name="Navigation-Servers"></A>Servers</H3>
<UL class="alternate" type="square">
<LI><A href="local-server.html" title="Local Server">Local</A></LI>
<LI><A href="remote-server.html" title="Remote Server">Remote</A></LI>
</UL>
<H3><A name="Navigation-Integrations"></A>Integrations</H3>
<UL class="alternate" type="square">
<LI><A href="../OPENEJBx30/tomcat.html" title="Tomcat">Tomcat</A></LI>
<LI><A href="geronimo.html" title="Geronimo">Geronimo</A></LI>
<LI><A href="webobjects.html" title="WebObjects">WebObjects</A></LI>
</UL>
<H3><A name="Navigation-Community"></A>Community</H3>
<UL class="alternate" type="square">
<LI><A href="team.html" title="Team">Team</A></LI>
<LI><A href="articles.html" title="Articles">Articles</A></LI>
<LI><A href="http://webchat.freenode.net/?channels=openejb" class="external-link" rel="nofollow">IRC</A></LI>
</UL>
<H3><A name="Navigation-RelatedProjects"></A>Related Projects</H3>
<UL class="alternate" type="square">
<LI><A href="http://activemq.apache.org/" class="external-link" rel="nofollow">ActiveMQ</A></LI>
<LI><A href="http://openjpa.apache.org/" class="external-link" rel="nofollow">OpenJPA</A></LI>
<LI><A href="http://cxf.apache.org/" class="external-link" rel="nofollow">CXF</A></LI>
</UL>
<H3><A name="Navigation-Index"></A>Index</H3>
<UL class="alternate" type="square">
<LI><A href="space-index.html" title="Space Index">Site Index</A></LI>
<LI><A href="../OPENEJBx30/space-index.html" title="Space Index">Doc Index</A></LI>
</UL>
<H3>
<A name="Navigation-Feeds"></A>
Feeds
</H3>
<UL class="feeds">
<LI>
<A href="http://cwiki.apache.org/confluence/spaces/rss.action?key=OPENEJB&newPages=false">
<IMG src="http://openejb.apache.org/images/rss.gif"></A>
<A class="feedsText" href="http://cwiki.apache.org/confluence/spaces/rss.action?key=OPENEJB&newPages=false">Site</A>
</LI>
<LI><A href="http://cwiki.apache.org/confluence/spaces/blogrss.action?key=OPENEJB">
<IMG src="http://openejb.apache.org/images/rss.gif"></A>
<A class="feedsText" href="http://cwiki.apache.org/confluence/spaces/blogrss.action?key=OPENEJB">News</A>
</LI>
</UL>
</SPAN>
</TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3">
<TABLE id="PageHeader" border="0" width="100%">
<TR>
<TD>
<A href="http://openejb.org/">
<IMG hspace="0" src="http://openejb.apache.org/images/logo_openejb.gif" vspace="0">
</A>
</TD>
<TD align="right">
<A href="http://www.apache.org/">
<IMG src="http://www.apache.org/images/asf-logo.gif" width="258" height="66">
</A>
</TD>
</TR>
<TR>
<TD id="page_title">
<!-- $TITLE -->
OSGi &amp; OpenEJB
</TD>
<TD align="right">
<BR><BR>
<!-- Google CSE Search Box Begins -->
<FORM id="searchbox_010475492895890475512:_t4iqjrgx90" action="http://www.google.com/cse">
<INPUT type="hidden" name="cx" value="010475492895890475512:_t4iqjrgx90">
<INPUT type="hidden" name="cof" value="FORID:0">
<INPUT name="q" type="text" size="25">
<INPUT type="submit" name="sa" value="Search">
</FORM>
<SCRIPT type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_010475492895890475512:_t4iqjrgx90"></SCRIPT>
<!-- Google CSE Search Box Ends -->
</TD>
</TR>
</TABLE>
<P>
<!-- $BODY -->
<DIV id="PageContent">
<H3><A name="OSGi%26OpenEJB-Gettingstarted"></A>Getting started</H3>
<P>The OpenEJB Eclipse plugin provides the org.apache.openejb.server plugin which can be run as an OSGi bundle in a container such as Equinox. </P>
<P>First of all, you will need to obtain the org.apache.openejb.server bundle. If you develop using Eclipse, you might want to consider installing the OpenEJB Eclipse Plugin, as this contains the necessary bundle. </P>
<P>I've provided a sample Equinox directory with OpenEJB and a sample EJB installed here: <A href="http://people.apache.org/~jgallimore/openejb-osgi.zip" class="external-link" rel="nofollow">http://people.apache.org/~jgallimore/openejb-osgi.zip</A> - the Eclipse projects for the EJB and client are here: <A href="http://people.apache.org/~jgallimore/projects.zip" class="external-link" rel="nofollow">http://people.apache.org/~jgallimore/projects.zip</A></P>
<P>If you wish to build the plugin, have a look at: <A href="http://cwiki.apache.org/confluence/display/OPENEJB/Building%20from%20source" class="external-link" rel="nofollow">http://cwiki.apache.org/confluence/display/OPENEJB/Building+from+source</A></P>
<H3><A name="OSGi%26OpenEJB-DeployingthebundleinEquinox"></A>Deploying the bundle in Equinox</H3>
<P>You can either use the OSGi console to deploy your bundles, or alternatively you can build a directory structure with all the necessary bundles and a config.ini.</P>
<P>The org.apache.openejb.server bundle has the following dependencies:</P>
<UL>
<LI>org.eclipse.core.contenttype</LI>
<LI>org.eclipse.core.jobs</LI>
<LI>org.eclipse.core.runtime</LI>
<LI>org.eclipse.core.variables</LI>
<LI>org.eclipse.equinox.app</LI>
<LI>org.eclipse.equinox.common</LI>
<LI>org.eclipse.equinox.launcher</LI>
<LI>org.eclipse.equinox.preferences</LI>
<LI>org.eclipse.equinox.registry</LI>
<LI>org.eclipse.osgi</LI>
</UL>
<P>These are most easily picked up from an existing Eclipse installation.</P>
<P>To deploy the org.apache.openejb.server bundle at the console, do the following:</P>
<P>Start the console:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
java -jar org.eclipse.osgi_3.4.0.jar -console
</PRE>
</DIV></DIV>
<P>Use the install command to deploy the bundle (you'll need to do this for the dependencies as well:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
osgi&gt; install file:<SPAN class="code-comment">///path/to/org.apache.openejb.server-1.0.2.jar</SPAN>
</PRE>
</DIV></DIV>
<P>You can view the installed bundles using the ss command:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
osgi&gt; ss
Framework is launched.
id State Bundle
0 ACTIVE org.eclipse.osgi_3.4.0.v20080605-1900
1 ACTIVE org.apache.openejb.server_1.0.2
2 &lt;&lt;LAZY&gt;&gt; org.eclipse.core.contenttype_3.3.0.v20080604-1400
3 ACTIVE org.eclipse.core.jobs_3.4.0.v20080512
4 ACTIVE org.eclipse.core.runtime_3.4.0.v20080512
5 ACTIVE org.eclipse.core.variables_3.2.100.v20080529-1300
6 ACTIVE org.eclipse.equinox.app_1.1.0.v20080421-2006
7 ACTIVE org.eclipse.equinox.common_3.4.0.v20080421-2006
8 ACTIVE org.eclipse.equinox.preferences_3.2.201.R34x_v20080709
9 ACTIVE org.eclipse.equinox.registry_3.4.0.v20080516-0950
10 ACTIVE test.ejb_1.0.0
11 &lt;&lt;LAZY&gt;&gt; test.ejb.client_1.0.0
12 RESOLVED org.eclipse.equinox.launcher_1.0.101.R34x_v20080819
</PRE>
</DIV></DIV>
<P>To create a directory structure instead, add the bundles you want to deploy into a directory, and add a config.ini file to a configuration subdirectory:</P>
<P><PRE>|-configuration
| |-config.ini
|
|-org.eclipse.core.contenttype.jar
|-org.eclipse.core.jobs.jar
|-org.eclipse.core.runtime.jar
|-org.eclipse.core.variables.jar
|-org.eclipse.equinox.app.jar
|-org.eclipse.equinox.common.jar
|-org.eclipse.equinox.launcher.jar
|-org.eclipse.equinox.preferences.jar
|-org.eclipse.equinox.registry.jar
|-org.eclipse.osgi.jar
</PRE> </P>
<P>config.ini needs to specify a osgi.bundles property in Java properties format (bundles with @start specified after them will be autostarted):</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
osgi.bundles=org.apache.openejb.server,org.eclipse.core.contenttype,org.eclipse.core.jobs,org.eclipse.core.runtime@start,...
</PRE>
</DIV></DIV>
<H3><A name="OSGi%26OpenEJB-CreatinganEJBbundle"></A>Creating an EJB bundle</H3>
<P>You will need to create an OSGi bundle to hold your EJBs. This could be an existing EJB jar, which you can add a manifest file to. This bundle will need to declare a dependency on org.apache.openejb.server in the manifest:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;"><B>META-INF/MANFEST.MF</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
...
Require-Bundle: org.apache.openejb.server;bundle-version=<SPAN class="code-quote">&quot;1.0.2&quot;</SPAN>
...
</PRE>
</DIV></DIV>
<P>Finally in the bundle Activator class, you will need to register an OSGi OpenEJBApplication service:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;"><B>Activator.java</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
Bundle bundle = context.getBundle();
OpenEjbApplication application = <SPAN class="code-keyword">new</SPAN> OpenEjbApplication(bundle);
context.registerService(OpenEjbApplication.class.getName(), application, <SPAN class="code-keyword">null</SPAN>);
</PRE>
</DIV></DIV>
<P>When your new bundle is deployed, you should see OpenEJB deploy your EJBs:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
osgi&gt; Apache OpenEJB 3.1.1-SNAPSHOT build: 20090424-12:35
http:<SPAN class="code-comment">//openejb.apache.org/
</SPAN>INFO - openejb.home = C:\Documents and Settings\Jon\openejb
INFO - openejb.base = D:\Temp\openejb-osgi\configuration\org.eclipse.osgi\bundles\1\1\.cp
INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Configuring enterprise application: D:\Temp\openejb-osgi\configuration\org.eclipse.osgi\bundles\10\1\.cp
INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
INFO - Auto-creating a container <SPAN class="code-keyword">for</SPAN> bean EchoImpl: Container(type=STATELESS, id=Default Stateless Container)
INFO - Enterprise application <SPAN class="code-quote">&quot;D:\Temp\openejb-osgi\configuration\org.eclipse.osgi\bundles\10\1\.cp&quot;</SPAN> loaded.
INFO - Assembling app: D:\Temp\openejb-osgi\configuration\org.eclipse.osgi\bundles\10\1\.cp
INFO - Jndi(name=EchoImplRemote) --&gt; Ejb(deployment-id=EchoImpl)
INFO - Jndi(name=EchoImplRemote) --&gt; Ejb(deployment-id=EchoImpl)
INFO - Created Ejb(deployment-id=EchoImpl, ejb-name=EchoImpl, container=Default
Stateless Container)
INFO - Deployed Application(path=D:\Temp\openejb-osgi\configuration\org.eclipse.osgi\bundles\10\1\.cp)
</PRE>
</DIV></DIV>
<H3><A name="OSGi%26OpenEJB-Creatingaclientbundle"></A>Creating a client bundle</H3>
<P>You can create a bundle to access your beans. This bundle will need to declare dependencies on both the bundle with your EJBs (which will need to export your bean interfaces) and also on org.apache.openejb.server:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;"><B>META-INF/MANIFEST.MF</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
...
Require-Bundle: test.ejb;bundle-version=<SPAN class="code-quote">&quot;1.0.0&quot;</SPAN>,
org.apache.openejb.server;bundle-version=<SPAN class="code-quote">&quot;1.0.2&quot;</SPAN>
...
</PRE>
</DIV></DIV>
<P>You can then access your beans in the usual way:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
Properties p = <SPAN class="code-keyword">new</SPAN> Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, <SPAN class="code-quote">&quot;org.apache.openejb.client.LocalInitialContextFactory&quot;</SPAN>);
InitialContext initialContext = <SPAN class="code-keyword">new</SPAN> InitialContext(p);
Echo server = (Echo) initialContext.lookup(<SPAN class="code-quote">&quot;EchoImplRemote&quot;</SPAN>);
server.echo(<SPAN class="code-quote">&quot;Hello world!&quot;</SPAN>);
</PRE>
</DIV></DIV>
</DIV>
</P>
</TD>
<TD class="Col4"><IMG src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">
</TD>
</TR>
<TR class="Row5">
<TD class="Col1">&nbsp;</TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3">
<BR>
<BR>
<IMG width="100%" height="1" src="http://openejb.apache.org/images/line_light.gif">
<TABLE width="100%">
<TR>
<TD>
<SPAN class="bodyGrey">
<SMALL>
<NOTICE><!-- $FOOTER -->
Apache OpenEJB is an project of The Apache Software Foundation (ASF)
</NOTICE>
<BR>
Site Powered by
<A href="http://atlassian.com/">Atlassian</A>
<A href="http://atlassian.com/confluence/">Confluence</A>
.
</SMALL>
</SPAN>
</TD>
<TD align="right">
<A style="color:#999;font-size:small;font-weight:normal;" href="https://cwiki.apache.org/confluence/pages/editpage.action?spaceKey=OPENEJB&title=OSGi%20&%20OpenEJB">[ edit ]</A>
</TD>
</TR>
</TABLE>
<BR>
</TD>
<TD class="Col4"><IMG src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">&nbsp;</TD>
</TR>
</TABLE>
<!-- Needed for composition plugin -->
<!-- delay the loading of large javascript files to the end so that they don't interfere with the loading of page content -->
<SPAN style="display: none">
<SCRIPT type="text/javascript" language="JavaScript" src="http://cwiki.apache.org/confluence/labels-javascript"></SCRIPT>
<SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</SCRIPT>
<SCRIPT type="text/javascript">
_uacct = "UA-2717626-1";
urchinTracker();
</SCRIPT>
</SPAN>
</BODY>
</HTML>