You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by "Brown, Deryck" <de...@ziebel.biz> on 2009/01/26 16:23:54 UTC

Dynamically deploying to an embedded OpenEJB server within an Eclipse RCP application

Hi,

 

I am trying to configure OpenEJB as part of an Eclipse rich-client
platform (RCP) application that I am developing.

 

I have managed to package OpenEJB 3.1 as an Eclipse plug-in by
"rebundling" the OpenEJB lib folder as an Eclipse RCP plug-in project.
This is to get round the problem with the javaee-api jar file not being
a valid OSGi bundle, but also to avoid generating a separate plug-in for
every jar file in the OpenEJB server.

 

So far, I have managed to get unit tests to work successfully with my
OpenEJB plug-in as a "buddy" of my plug-in that defines the EJBs. I am
running the tests in a fragment of the EJB plug-in. However, this relied
on the test plug-in to configure and start the OpenEJB server, something
I'm not particularly happy with.

 

Anyway, I'm currently trying to get OpenEJB to start the server when its
plug-in is activated, and then deploy and undeploy applications when
other plug-ins are started and stopped. This would use the OSGi service
framework and the so-called "white-board" model (see [1]).

 

However, for this to work, I must be able to dynamically deploy an
application on the local server after the server has started (and, for
example, after the test plug-in fragment has properly configured the
test database for my EJBs). This is where I am having problems. I've
spent some time looking through the OpenEJB source to try and work out
how an application is deployed, and I think I want to use the
Deployer.deploy() method from the DeployerEjb class. Alas, I cannot work
out how to get access to this object from within my own code. As far as
I can see, the only examples of using this method directly in the
OpenEJB code rely on doing a JNDI lookup of
"openejb/DeployerBusinessRemote", and this name does not appear to be
bound in a local server.

 

Can anyone point me towards examples of deploying and undeploying
applications on a local OpenEJB server from within Java code?

 

Many thanks,

Deryck Brown

 

References

 

[1] http://www.knopflerfish.org/osgi_service_tutorial.html#white

 

-- 

Dr Deryck F Brown

Software Engineer

Ziebel UK Ltd

Unit A, Broadfold Road,

Bridge of Don,

Aberdeen AB23 8EE

 


Re: Dynamically deploying to an embedded OpenEJB server within an Eclipse RCP application

Posted by Jonathan Gallimore <jo...@gmail.com>.
Brown, Deryck wrote:
> JIRA issue now created with the source attached and permission for
> inclusion granted.
>
> See http://issues.apache.org/jira/browse/OPENEJB-1000
>   
Many thanks for this, I've added your plugins to our SVN repository at 
http://svn.apache.org/repos/asf/openejb/trunk/sandbox/openejb-eclipse-plugin/

I've "Mavenized" the openejb.server plugin, and added the standard ASF 
headers. I'll get the other two plugins building with Maven hopefully 
this week.
> (Do I get a prize for being OpenEJB issue #1000? :-)
>
>   
You should definitely get a prize for issue 1000 - sorry I moved it to 
OEP-24 ;-)

Cheers

Jon

RE: Dynamically deploying to an embedded OpenEJB server within an Eclipse RCP application

Posted by "Brown, Deryck" <de...@ziebel.biz>.
David and Jonathan,

>> David, am I right in thinking we need Deryck to attach this to a  
>> JIRA and tick the box giving us permission to use this before we can

>> go any further?
>
>Exactly right.
>
>-David

JIRA issue now created with the source attached and permission for
inclusion granted.

See http://issues.apache.org/jira/browse/OPENEJB-1000

(Do I get a prize for being OpenEJB issue #1000? :-)

Regards,
Deryck

-- 
Dr Deryck F Brown
Software Engineer
Ziebel UK Ltd
Unit A, Broadfold Road,
Bridge of Don,
Aberdeen AB23 8EE
 
Tel: 01224 227227 (X143)
Fax: 01224 703146
Skype: ziebel-deryckb
Web: www.ziebel.biz

Re: Dynamically deploying to an embedded OpenEJB server within an Eclipse RCP application

Posted by David Blevins <da...@visi.com>.
On Feb 13, 2009, at 4:35 AM, Jonathan Gallimore wrote:

> I spent a couple of hours playing with this last night, and it looks  
> awesome to me! Personally I will find this very useful, and I'm sure  
> many others will too.
>
> I think it would be great if we can offer this along side our other  
> Eclipse plugins. Deryck, if you're happy for this to go into our SVN  
> repository, I can add some Maven POMs and get it checked in.
>
> David, am I right in thinking we need Deryck to attach this to a  
> JIRA and tick the box giving us permission to use this before we can  
> go any further?

Exactly right.

-David


>
> David Blevins wrote:
>> Hi Deryck,
>>
>> This is a pretty amazing contribution.  I'd definitely like to see  
>> this go somewhere so other users could benefit.  I'm not much of an  
>> Eclipse guy, Cc'ing Jonathan who has done some great OpenEJB/ 
>> Eclipse work to see if he has any thoughts on how to incorporate  
>> this into the codebase.
>>
>> Offhand I wonder how close this is to being a general OSGi solution  
>> non-specific to Eclipse.  Not at all a requirement as something is  
>> better than nothing, but interested in your thoughts.
>>
>> Definitely a very exciting bit of code!  I suspect a lot of people  
>> will owe you a beer :)
>>
>> -David
>>
>> On Feb 4, 2009, at 1:52 AM, Brown, Deryck wrote:
>>
>>> Hi David and Donatas,
>>>
>>> I've been working some more on creating an OpenEJB plug-in that  
>>> would
>>> allow applications held in other plug-ins to be deployed when their
>>> plug-in is activated.
>>>
>>> This is based on a single OpenEJB server plug-in that contains all  
>>> of
>>> the OpenEJB libraries and some additional classes to activate and  
>>> manage
>>> the deployment of other applications.
>>>
>>> I've managed to get some examples working, and thought it would be  
>>> good
>>> to share my efforts with you so far.
>>>
>>> The attached Zip file contains three Eclipse projects, the server
>>> plug-in and a simple EchoServer stateless bean application and a  
>>> client.
>>>
>>> The server plug-in I've created allows for deployment when a plug-in
>>> registers a new OpenEjbApplication as a service. The OpenEJB server
>>> plug-in listens for service requests and automatically deploys and
>>> undeploys an application when the service starts and stops.
>>>
>>> The only problem with this approach is making sure the application
>>> plug-in is activated before the client tries to use it (e.g., by  
>>> making
>>> a context lookup). This is handled in the activation code of the  
>>> client
>>> by forcing the application plug-in to start.
>>>
>>> The code I've written allows additional application properties to be
>>> included as part of the normal Eclipse service creation. You can  
>>> get the
>>> OpenEJB server plug-in to load properties from files included in the
>>> application plug-in and any fragments (I use META-INF/ 
>>> openejb.properties
>>> in my EJB plug-in). Because of the Eclipse plug-in/fragment  
>>> arrangement,
>>> if you include a file with the same name in a fragment, its  
>>> properties
>>> will override those found in the host plug-in. However, the order of
>>> fragment processing is undefined, and so you cannot reliably  
>>> override
>>> properties between fragments.
>>>
>>> Also, the properties are processed using the Eclipse variables API  
>>> to
>>> handle string substitution, so that, for example, a property can  
>>> include
>>> ${user.home} and get this expanded before it is passed to the  
>>> OpenEJB
>>> server. I automatically add all System.getProperties() to the  
>>> variables
>>> available, as well as any properties added by the application.
>>>
>>> I need this overriding and substitution to allow my test fragment
>>> project to override the database URL of the main EJB plug-in to  
>>> use a
>>> different test database, and to have the database location depend  
>>> on the
>>> user's home directory.
>>>
>>> To get the example working, you will need to create a folder in the
>>> openejb.server project that is a link to the OpenEJB 3.1 lib  
>>> folder in
>>> the distribution. Also, make sure that all of the OpenEJB  
>>> libraries are
>>> included in the project build path and exported by the project.
>>>
>>> You are likely to have many more questions about this code than I've
>>> provided answers to in this short email, but I thought it was time  
>>> share
>>> where I have reached so far.
>>>
>>> Regards,
>>> Deryck
>>>
>>> -- 
>>> Dr Deryck F Brown
>>> Software Engineer
>>> Ziebel UK Ltd
>>> Unit A, Broadfold Road,
>>> Bridge of Don,
>>> Aberdeen AB23 8EE
>>>
>>> Tel: 01224 227227 (X143)
>>> Fax: 01224 703146
>>> Skype: ziebel-deryckb
>>> Web: www.ziebel.biz
>>>
>>> <example.zip>
>>
>


Re: Dynamically deploying to an embedded OpenEJB server within an Eclipse RCP application

Posted by Jonathan Gallimore <jo...@gmail.com>.
I spent a couple of hours playing with this last night, and it looks 
awesome to me! Personally I will find this very useful, and I'm sure 
many others will too.

I think it would be great if we can offer this along side our other 
Eclipse plugins. Deryck, if you're happy for this to go into our SVN 
repository, I can add some Maven POMs and get it checked in.

David, am I right in thinking we need Deryck to attach this to a JIRA 
and tick the box giving us permission to use this before we can go any 
further?

Cheers

Jon




David Blevins wrote:
> Hi Deryck,
>
> This is a pretty amazing contribution.  I'd definitely like to see 
> this go somewhere so other users could benefit.  I'm not much of an 
> Eclipse guy, Cc'ing Jonathan who has done some great OpenEJB/Eclipse 
> work to see if he has any thoughts on how to incorporate this into the 
> codebase.
>
> Offhand I wonder how close this is to being a general OSGi solution 
> non-specific to Eclipse.  Not at all a requirement as something is 
> better than nothing, but interested in your thoughts.
>
> Definitely a very exciting bit of code!  I suspect a lot of people 
> will owe you a beer :)
>
> -David
>
> On Feb 4, 2009, at 1:52 AM, Brown, Deryck wrote:
>
>> Hi David and Donatas,
>>
>> I've been working some more on creating an OpenEJB plug-in that would
>> allow applications held in other plug-ins to be deployed when their
>> plug-in is activated.
>>
>> This is based on a single OpenEJB server plug-in that contains all of
>> the OpenEJB libraries and some additional classes to activate and manage
>> the deployment of other applications.
>>
>> I've managed to get some examples working, and thought it would be good
>> to share my efforts with you so far.
>>
>> The attached Zip file contains three Eclipse projects, the server
>> plug-in and a simple EchoServer stateless bean application and a client.
>>
>> The server plug-in I've created allows for deployment when a plug-in
>> registers a new OpenEjbApplication as a service. The OpenEJB server
>> plug-in listens for service requests and automatically deploys and
>> undeploys an application when the service starts and stops.
>>
>> The only problem with this approach is making sure the application
>> plug-in is activated before the client tries to use it (e.g., by making
>> a context lookup). This is handled in the activation code of the client
>> by forcing the application plug-in to start.
>>
>> The code I've written allows additional application properties to be
>> included as part of the normal Eclipse service creation. You can get the
>> OpenEJB server plug-in to load properties from files included in the
>> application plug-in and any fragments (I use META-INF/openejb.properties
>> in my EJB plug-in). Because of the Eclipse plug-in/fragment arrangement,
>> if you include a file with the same name in a fragment, its properties
>> will override those found in the host plug-in. However, the order of
>> fragment processing is undefined, and so you cannot reliably override
>> properties between fragments.
>>
>> Also, the properties are processed using the Eclipse variables API to
>> handle string substitution, so that, for example, a property can include
>> ${user.home} and get this expanded before it is passed to the OpenEJB
>> server. I automatically add all System.getProperties() to the variables
>> available, as well as any properties added by the application.
>>
>> I need this overriding and substitution to allow my test fragment
>> project to override the database URL of the main EJB plug-in to use a
>> different test database, and to have the database location depend on the
>> user's home directory.
>>
>> To get the example working, you will need to create a folder in the
>> openejb.server project that is a link to the OpenEJB 3.1 lib folder in
>> the distribution. Also, make sure that all of the OpenEJB libraries are
>> included in the project build path and exported by the project.
>>
>> You are likely to have many more questions about this code than I've
>> provided answers to in this short email, but I thought it was time share
>> where I have reached so far.
>>
>> Regards,
>> Deryck
>>
>> -- 
>> Dr Deryck F Brown
>> Software Engineer
>> Ziebel UK Ltd
>> Unit A, Broadfold Road,
>> Bridge of Don,
>> Aberdeen AB23 8EE
>>
>> Tel: 01224 227227 (X143)
>> Fax: 01224 703146
>> Skype: ziebel-deryckb
>> Web: www.ziebel.biz
>>
>> <example.zip>
>


Re: Dynamically deploying to an embedded OpenEJB server within an Eclipse RCP application

Posted by David Blevins <da...@visi.com>.
Hi Deryck,

This is a pretty amazing contribution.  I'd definitely like to see  
this go somewhere so other users could benefit.  I'm not much of an  
Eclipse guy, Cc'ing Jonathan who has done some great OpenEJB/Eclipse  
work to see if he has any thoughts on how to incorporate this into the  
codebase.

Offhand I wonder how close this is to being a general OSGi solution  
non-specific to Eclipse.  Not at all a requirement as something is  
better than nothing, but interested in your thoughts.

Definitely a very exciting bit of code!  I suspect a lot of people  
will owe you a beer :)

-David

On Feb 4, 2009, at 1:52 AM, Brown, Deryck wrote:

> Hi David and Donatas,
>
> I've been working some more on creating an OpenEJB plug-in that would
> allow applications held in other plug-ins to be deployed when their
> plug-in is activated.
>
> This is based on a single OpenEJB server plug-in that contains all of
> the OpenEJB libraries and some additional classes to activate and  
> manage
> the deployment of other applications.
>
> I've managed to get some examples working, and thought it would be  
> good
> to share my efforts with you so far.
>
> The attached Zip file contains three Eclipse projects, the server
> plug-in and a simple EchoServer stateless bean application and a  
> client.
>
> The server plug-in I've created allows for deployment when a plug-in
> registers a new OpenEjbApplication as a service. The OpenEJB server
> plug-in listens for service requests and automatically deploys and
> undeploys an application when the service starts and stops.
>
> The only problem with this approach is making sure the application
> plug-in is activated before the client tries to use it (e.g., by  
> making
> a context lookup). This is handled in the activation code of the  
> client
> by forcing the application plug-in to start.
>
> The code I've written allows additional application properties to be
> included as part of the normal Eclipse service creation. You can get  
> the
> OpenEJB server plug-in to load properties from files included in the
> application plug-in and any fragments (I use META-INF/ 
> openejb.properties
> in my EJB plug-in). Because of the Eclipse plug-in/fragment  
> arrangement,
> if you include a file with the same name in a fragment, its properties
> will override those found in the host plug-in. However, the order of
> fragment processing is undefined, and so you cannot reliably override
> properties between fragments.
>
> Also, the properties are processed using the Eclipse variables API to
> handle string substitution, so that, for example, a property can  
> include
> ${user.home} and get this expanded before it is passed to the OpenEJB
> server. I automatically add all System.getProperties() to the  
> variables
> available, as well as any properties added by the application.
>
> I need this overriding and substitution to allow my test fragment
> project to override the database URL of the main EJB plug-in to use a
> different test database, and to have the database location depend on  
> the
> user's home directory.
>
> To get the example working, you will need to create a folder in the
> openejb.server project that is a link to the OpenEJB 3.1 lib folder in
> the distribution. Also, make sure that all of the OpenEJB libraries  
> are
> included in the project build path and exported by the project.
>
> You are likely to have many more questions about this code than I've
> provided answers to in this short email, but I thought it was time  
> share
> where I have reached so far.
>
> Regards,
> Deryck
>
> -- 
> Dr Deryck F Brown
> Software Engineer
> Ziebel UK Ltd
> Unit A, Broadfold Road,
> Bridge of Don,
> Aberdeen AB23 8EE
>
> Tel: 01224 227227 (X143)
> Fax: 01224 703146
> Skype: ziebel-deryckb
> Web: www.ziebel.biz
>
> <example.zip>


RE: Dynamically deploying to an embedded OpenEJB server within an Eclipse RCP application

Posted by "Brown, Deryck" <de...@ziebel.biz>.
Hi David and Donatas,

I've been working some more on creating an OpenEJB plug-in that would
allow applications held in other plug-ins to be deployed when their
plug-in is activated.

This is based on a single OpenEJB server plug-in that contains all of
the OpenEJB libraries and some additional classes to activate and manage
the deployment of other applications.

I've managed to get some examples working, and thought it would be good
to share my efforts with you so far.

The attached Zip file contains three Eclipse projects, the server
plug-in and a simple EchoServer stateless bean application and a client.

The server plug-in I've created allows for deployment when a plug-in
registers a new OpenEjbApplication as a service. The OpenEJB server
plug-in listens for service requests and automatically deploys and
undeploys an application when the service starts and stops.

The only problem with this approach is making sure the application
plug-in is activated before the client tries to use it (e.g., by making
a context lookup). This is handled in the activation code of the client
by forcing the application plug-in to start.

The code I've written allows additional application properties to be
included as part of the normal Eclipse service creation. You can get the
OpenEJB server plug-in to load properties from files included in the
application plug-in and any fragments (I use META-INF/openejb.properties
in my EJB plug-in). Because of the Eclipse plug-in/fragment arrangement,
if you include a file with the same name in a fragment, its properties
will override those found in the host plug-in. However, the order of
fragment processing is undefined, and so you cannot reliably override
properties between fragments.

Also, the properties are processed using the Eclipse variables API to
handle string substitution, so that, for example, a property can include
${user.home} and get this expanded before it is passed to the OpenEJB
server. I automatically add all System.getProperties() to the variables
available, as well as any properties added by the application.

I need this overriding and substitution to allow my test fragment
project to override the database URL of the main EJB plug-in to use a
different test database, and to have the database location depend on the
user's home directory.

To get the example working, you will need to create a folder in the
openejb.server project that is a link to the OpenEJB 3.1 lib folder in
the distribution. Also, make sure that all of the OpenEJB libraries are
included in the project build path and exported by the project.

You are likely to have many more questions about this code than I've
provided answers to in this short email, but I thought it was time share
where I have reached so far.

Regards,
Deryck

-- 
Dr Deryck F Brown
Software Engineer
Ziebel UK Ltd
Unit A, Broadfold Road,
Bridge of Don,
Aberdeen AB23 8EE
 
Tel: 01224 227227 (X143)
Fax: 01224 703146
Skype: ziebel-deryckb
Web: www.ziebel.biz 


Re: Dynamically deploying to an embedded OpenEJB server within an Eclipse RCP application

Posted by Do...@mif.vu.lt.
Hi Deryck,

As David mentioned, I'm trying to solve similar problem, though I was  
less successful. You could read about my trial in mail archive:

http://www.mail-archive.com/dev@openejb.apache.org/msg03187.html

In short: I created plugin from OpenEJB libs too, this plugin has  
Eclipse-BuddyPolicy: registered, my main plugin has  
META-INF/ejb-jar.xml, main plugin tries to create InitialContext(),  
OpenEJB starts loading and crashes with Exceptions.

I would be interested to see your Manifest.mf entries, and the way you  
configure and start OpenEJB.

Thanks,
Donatas

David Blevins <da...@visi.com> rašė:

>
> On Jan 26, 2009, at 7:23 AM, Brown, Deryck wrote:
>
>> Hi,
>>
>>
>>
>> I am trying to configure OpenEJB as part of an Eclipse rich-client
>> platform (RCP) application that I am developing.
>>
>>
>>
>> I have managed to package OpenEJB 3.1 as an Eclipse plug-in by
>> "rebundling" the OpenEJB lib folder as an Eclipse RCP plug-in project.
>> This is to get round the problem with the javaee-api jar file not being
>> a valid OSGi bundle, but also to avoid generating a separate plug-in for
>> every jar file in the OpenEJB server.
>
> The 3.1.1 release will include a javaee-api jar that has the  
> required OSGi bundle information in it.  (Thanks again Oliver  
> Gunther for that!)
>
>> So far, I have managed to get unit tests to work successfully with my
>> OpenEJB plug-in as a "buddy" of my plug-in that defines the EJBs. I am
>> running the tests in a fragment of the EJB plug-in. However, this relied
>> on the test plug-in to configure and start the OpenEJB server, something
>> I'm not particularly happy with.
>
> I've Cc'ed another user who posted to dev@openejb.a.o about doing  
> that same thing.  If you could give some details that'd be great.   
> (or Donatas can ask questions)
>
>> Anyway, I'm currently trying to get OpenEJB to start the server when its
>> plug-in is activated, and then deploy and undeploy applications when
>> other plug-ins are started and stopped. This would use the OSGi service
>> framework and the so-called "white-board" model (see [1]).
>>
>> However, for this to work, I must be able to dynamically deploy an
>> application on the local server after the server has started (and, for
>> example, after the test plug-in fragment has properly configured the
>> test database for my EJBs). This is where I am having problems. I've
>> spent some time looking through the OpenEJB source to try and work out
>> how an application is deployed, and I think I want to use the
>> Deployer.deploy() method from the DeployerEjb class. Alas, I cannot work
>> out how to get access to this object from within my own code. As far as
>> I can see, the only examples of using this method directly in the
>> OpenEJB code rely on doing a JNDI lookup of
>> "openejb/DeployerBusinessRemote", and this name does not appear to be
>> bound in a local server.
>>
>> Can anyone point me towards examples of deploying and undeploying
>> applications on a local OpenEJB server from within Java code?
>
> You can enable the deployer EJB in an embedded mode by adding this  
> system property:
>
>   openejb.deployments.classpath.filter.systemapps = true
>
> Then you can lookup and use the DeployerEjb to deploy any apps you need.
>
> Let us know how that goes as we have a few users in your same bucket.
>
> -David
>
>



Re: Dynamically deploying to an embedded OpenEJB server within an Eclipse RCP application

Posted by David Blevins <da...@visi.com>.
On Jan 26, 2009, at 7:23 AM, Brown, Deryck wrote:

> Hi,
>
>
>
> I am trying to configure OpenEJB as part of an Eclipse rich-client
> platform (RCP) application that I am developing.
>
>
>
> I have managed to package OpenEJB 3.1 as an Eclipse plug-in by
> "rebundling" the OpenEJB lib folder as an Eclipse RCP plug-in project.
> This is to get round the problem with the javaee-api jar file not  
> being
> a valid OSGi bundle, but also to avoid generating a separate plug-in  
> for
> every jar file in the OpenEJB server.

The 3.1.1 release will include a javaee-api jar that has the required  
OSGi bundle information in it.  (Thanks again Oliver Gunther for that!)

> So far, I have managed to get unit tests to work successfully with my
> OpenEJB plug-in as a "buddy" of my plug-in that defines the EJBs. I am
> running the tests in a fragment of the EJB plug-in. However, this  
> relied
> on the test plug-in to configure and start the OpenEJB server,  
> something
> I'm not particularly happy with.

I've Cc'ed another user who posted to dev@openejb.a.o about doing that  
same thing.  If you could give some details that'd be great.  (or  
Donatas can ask questions)

> Anyway, I'm currently trying to get OpenEJB to start the server when  
> its
> plug-in is activated, and then deploy and undeploy applications when
> other plug-ins are started and stopped. This would use the OSGi  
> service
> framework and the so-called "white-board" model (see [1]).
>
> However, for this to work, I must be able to dynamically deploy an
> application on the local server after the server has started (and, for
> example, after the test plug-in fragment has properly configured the
> test database for my EJBs). This is where I am having problems. I've
> spent some time looking through the OpenEJB source to try and work out
> how an application is deployed, and I think I want to use the
> Deployer.deploy() method from the DeployerEjb class. Alas, I cannot  
> work
> out how to get access to this object from within my own code. As far  
> as
> I can see, the only examples of using this method directly in the
> OpenEJB code rely on doing a JNDI lookup of
> "openejb/DeployerBusinessRemote", and this name does not appear to be
> bound in a local server.
>
> Can anyone point me towards examples of deploying and undeploying
> applications on a local OpenEJB server from within Java code?

You can enable the deployer EJB in an embedded mode by adding this  
system property:

   openejb.deployments.classpath.filter.systemapps = true

Then you can lookup and use the DeployerEjb to deploy any apps you need.

Let us know how that goes as we have a few users in your same bucket.

-David