You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by hemilshah <he...@lntinfotech.com> on 2010/03/24 11:03:47 UTC

How to use OpenEJB with Tomcat

Hi,

Please brief me about using OpenEJB with Tomcat. I am confuse with two
different paths -

1) Using OpenEJB as standalone server
2) Integrating openejb with Tomcat.

Basically, i want to use EJBs with Tomcat so i have integrated it with
Tomcat as specified on website, but i am unable to deploy EJB. For that it
seems i need use OpenEJB server separately. So is it really required. Just
integrating with Tomcat is not sufficient ? And if it is sufficient, how
shall i deploy EJB to OpenEJB on Tomcat server ?

Please clarify me about this.

THanks.
Regards,
Hemil
-- 
View this message in context: http://n4.nabble.com/How-to-use-OpenEJB-with-Tomcat-tp1680307p1680307.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: How to use OpenEJB with Tomcat

Posted by Jean-Louis MONTEIRO <je...@atosorigin.com>.
Hi Hemil,

Not sure to understand what's the problem.
First did you successfully install OpenEJB in Tomcat? (
http://openejb.apache.org/tomcat.html http://openejb.apache.org/tomcat.html
).

If it works, then you only have to create a war file (containing your EJBs)
and deploy it in Tomcat using the Tomcat manager or just putting your war in
the webapp/ directory.

Can you elaborate a bit more?
Thanks.

Jean-Louis


hemilshah wrote:
> 
> Hi,
> 
> Please brief me about using OpenEJB with Tomcat. I am confuse with two
> different paths -
> 
> 1) Using OpenEJB as standalone server
> 2) Integrating openejb with Tomcat.
> 
> Basically, i want to use EJBs with Tomcat so i have integrated it with
> Tomcat as specified on website, but i am unable to deploy EJB. For that it
> seems i need use OpenEJB server separately. So is it really required. Just
> integrating with Tomcat is not sufficient ? And if it is sufficient, how
> shall i deploy EJB to OpenEJB on Tomcat server ?
> 
> Please clarify me about this.
> 
> THanks.
> Regards,
> Hemil
> 

-- 
View this message in context: http://n4.nabble.com/How-to-use-OpenEJB-with-Tomcat-tp1680307p1690507.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: How to use OpenEJB with Tomcat

Posted by Minh <bm...@hotmail.com>.
http://n4.nabble.com/file/n2125831/jar_list.jpg 
-- 
View this message in context: http://openejb.979440.n4.nabble.com/How-to-use-OpenEJB-with-Tomcat-tp1680307p2125831.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: How to use OpenEJB with Tomcat

Posted by Jean-Louis MONTEIRO <je...@atosorigin.com>.
Hey,

could you give us the WEB-INF/lib content (jar list)?

Jean-Louis


Minh wrote:
> 
> thanks Matthias ,
> 
> It works fine if I access the EJB bean in the same war file?
> Now, can you show me how to access / refer or invoke this bean from
> another WAR file or another applicaiton in the same Tomcat env?
> 
> 
> Thanks
> minh
> 

-- 
View this message in context: http://openejb.979440.n4.nabble.com/How-to-use-OpenEJB-with-Tomcat-tp1680307p2125091.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: How to use OpenEJB with Tomcat

Posted by Minh <bm...@hotmail.com>.
thanks Matthias ,

It works fine if I access the EJB bean in the same war file?
Now, can you show me how to access / refer or invoke this bean from another
WAR file or another applicaiton in the same Tomcat env?


Thanks
minh
-- 
View this message in context: http://openejb.979440.n4.nabble.com/How-to-use-OpenEJB-with-Tomcat-tp1680307p2124573.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: How to use OpenEJB with Tomcat

Posted by Matthias Wessendorf <ma...@apache.org>.
Hello Minh,

usually it is very simple.

Download the openejb.war from here:
http://www.apache.org/dist/openejb/3.1.2/

deploy it (as openejb.war) to tomcat's webapp folder

go to localhost:8080/openejb and run the "tests".
I'd also do the install (for the agent).

Than you could checkout this example:
https://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/webapps/jsf/

=> Follow the instructions in the README.txt

If you want a modern version of JSF2 (MyFaces2), feel free to
apply this patch:
https://issues.apache.org/jira/browse/OPENEJB-1264

-Matthias

On Thu, Apr 29, 2010 at 11:48 PM, Minh <bm...@hotmail.com> wrote:
>
> Please someone help me. I have tried this for 2 full days and not able to get
> a simple OpenEJB works on Tomcat.
>
> Not sure why I could not lookup the EJB bean...the example is very simple.
> the lookup always return NULL.
>
> On tomcat startup, i saw this error, but nit sure it is related to the
> problem,
>
> Apr 29, 2010 2:41:57 PM org.apache.catalina.loader.WebappClassLoader
> validateJarFile
> INFO:
> validateJarFile(C:\apache-tomcat-6.0.20\webapps\recharge_report\WEB-INF\lib\javaee-api-5.0-2.jar)
> - jar not loaded. See Servlet Spec 2.3, section 9.7
> .2. Offending class: javax/servlet/Servlet.class
> context path = /recharge_report
>
> And here is my classes:
>
>
> ------------------------------------------
> package edu.ucsd.ehs.service.helloworld;
>
> import javax.ejb.Stateless;
>
> @Stateless
> public class HelloBean implements Hello {
>
>    public String greet(String s) {
>        return "Hello " + s + "!";
>    }
> }
>
>
>
>
>
> package edu.ucsd.ehs.service.helloworld;
> import javax.ejb.Local;
>
> @Local
> public interface Hello{
>
>    public String greet(String s);
>
> }
>
> ----------------------------------------------
>
>
> And below is my struts action class where I look up for the bean and execute
> its method
>
>
>
>
>
> public class HomeAction extends DispatchAction  {
>
>        @EJB
>        private Hello bean;
>        public ActionForward displayHome(ActionMapping mapping, ActionForm form,
>                                             HttpServletRequest request, HttpServletResponse
> response)throws Exception {
>
>
>
>
>                System.out.println("***Context: HomeAction ");
>                try{
>                        System.out.println("***HomeAction: testing OPENEJB");
>                        String returnedString = bean.greet("OpenEJB User");
>                        System.out.println("***returnedString: " + returnedString);
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/How-to-use-OpenEJB-with-Tomcat-tp1680307p2076241.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>



-- 
Matthias Wessendorf

blog: http://matthiaswessendorf.wordpress.com/
sessions: http://www.slideshare.net/mwessendorf
twitter: http://twitter.com/mwessendorf

Re: How to use OpenEJB with Tomcat

Posted by Jean-Louis MONTEIRO <je...@atosorigin.com>.

Minh wrote:
> 
> Apr 29, 2010 2:41:57 PM org.apache.catalina.loader.WebappClassLoader
> validateJarFile
> INFO:
> validateJarFile(C:\apache-tomcat-6.0.20\webapps\recharge_report\WEB-INF\lib\javaee-api-5.0-2.jar)
> - jar not loaded. See Servlet Spec 2.3, section 9.7
> .2. Offending class: javax/servlet/Servlet.class
> context path = /recharge_report
> 
Regarding your jar list, i can understand why you get this exception.
Anyway, i don't see something special in your web application.

Did you check if the installer page works fine (I mean all is installed)?
Then, do you have a log you could provide?

Jean-Louis
-- 
View this message in context: http://openejb.979440.n4.nabble.com/How-to-use-OpenEJB-with-Tomcat-tp1680307p2126215.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: How to use OpenEJB with Tomcat

Posted by Minh <bm...@hotmail.com>.
Please someone help me. I have tried this for 2 full days and not able to get
a simple OpenEJB works on Tomcat.

Not sure why I could not lookup the EJB bean...the example is very simple. 
the lookup always return NULL.

On tomcat startup, i saw this error, but nit sure it is related to the
problem,

Apr 29, 2010 2:41:57 PM org.apache.catalina.loader.WebappClassLoader
validateJarFile
INFO:
validateJarFile(C:\apache-tomcat-6.0.20\webapps\recharge_report\WEB-INF\lib\javaee-api-5.0-2.jar)
- jar not loaded. See Servlet Spec 2.3, section 9.7
.2. Offending class: javax/servlet/Servlet.class
context path = /recharge_report

And here is my classes:


------------------------------------------
package edu.ucsd.ehs.service.helloworld;

import javax.ejb.Stateless;

@Stateless
public class HelloBean implements Hello {

    public String greet(String s) {
        return "Hello " + s + "!";
    }
}





package edu.ucsd.ehs.service.helloworld;
import javax.ejb.Local;

@Local
public interface Hello{

    public String greet(String s);

}

----------------------------------------------


And below is my struts action class where I look up for the bean and execute
its method





public class HomeAction extends DispatchAction  {

	@EJB
	private Hello bean;
	public ActionForward displayHome(ActionMapping mapping, ActionForm form,	
			                     HttpServletRequest request, HttpServletResponse
response)throws Exception {
 
		
		
		
		System.out.println("***Context: HomeAction ");
		try{
			System.out.println("***HomeAction: testing OPENEJB");
			String returnedString = bean.greet("OpenEJB User");
			System.out.println("***returnedString: " + returnedString);
			
			

-- 
View this message in context: http://openejb.979440.n4.nabble.com/How-to-use-OpenEJB-with-Tomcat-tp1680307p2076241.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: How to use OpenEJB with Tomcat

Posted by Jonathan Gallimore <jo...@gmail.com>.
Hi Hemil,

You do not need the standalone server, using openejb.war is sufficient. You
will need to package your EJBs up into a JAR, WAR or EAR, and copy that to
Tomcat's webapps directory.

You might need to define your JMS topic/queues in openejb.xml in Tomcat's
conf directory, but I personally haven't ever needed to.

Regards

Jon

On Mon, Mar 29, 2010 at 9:44 AM, hemilshah <he...@lntinfotech.com>wrote:

>
> Hi,
>
> My question is simple.
>
> If i want to use openejb with Tomcat, do i need to use openejb standalone
> server or just deploying openejb.war file is sufficient.
>
> If using openejb.war file is sufficient then how where will i specify EJB
> deployment related details like EJB beans, JMS queue (used for MDB).
>
> Thanks.
> Regards,
> Hemil
> --
> View this message in context:
> http://n4.nabble.com/How-to-use-OpenEJB-with-Tomcat-tp1680307p1694860.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: How to use OpenEJB with Tomcat

Posted by hemilshah <he...@lntinfotech.com>.
Hi,

My question is simple. 

If i want to use openejb with Tomcat, do i need to use openejb standalone
server or just deploying openejb.war file is sufficient.

If using openejb.war file is sufficient then how where will i specify EJB
deployment related details like EJB beans, JMS queue (used for MDB).

Thanks.
Regards,
Hemil
-- 
View this message in context: http://n4.nabble.com/How-to-use-OpenEJB-with-Tomcat-tp1680307p1694860.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: How to use OpenEJB with Tomcat

Posted by Jonathan Gallimore <jo...@gmail.com>.
Hi,

I'm not completely sure what you want to do, but I'll do my best to answer
your question. You mention that you were running Tomcat in Eclipse in
another post (
http://n4.nabble.com/Tomcat-Integration-problem-td1678990.html#a1680356)
which is perhaps adding to some of the confusion. Although we do have an
OpenEJB plugin for the WTP functionality, it currently does not support
Tomcat, only the standalone OpenEJB server.

I've been looking at a looking at a contribution from Jean-Sébastien Scrève
to add Tomcat support to the Eclipse plugin, but have not completed the work
to integrate it yet (https://issues.apache.org/jira/browse/OEP-32). I'd be
happy to get back onto it once I've cleared a couple of other things off my
plate. Or I'd be happy to help if anyone else wants to have a go.

Anyway, back to your question -

There's essentially three different ways you can run OpenEJB: Embedded,
Standalone and in Tomcat.

Embedded:
---------------

Running OpenEJB in this mode makes it really easy to test your EJBs. As long
as you setup your class path correctly you can start OpenEJB in Embedded
mode by adding the following code to your test:

Properties p = new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
InitialContext context = new InitialContext(p);

This will scan your classpath and deploy any EJBs it finds.

You can lookup your beans using the usual:

EJBObject obj = (EJBObject) context.lookup("EJBJNDIName");

where EJBObject is your EJB's interface, and EJBJNDIName is your EJB's JNDI
name.

David has put together a video showing how to use the embedded mode to test
EJBs in Eclipse: http://vimeo.com/6149008


Standalone
---------------

You can run the OpenEJB server in standalone mode, this provides an EJB
container that you can access remotely. You can download the standalone
server from here:
http://www.apache.org/dyn/closer.cgi/openejb/3.1.2/openejb-3.1.2.zip. Unzip
this, and create two folders in the openejb folder called apps and logs.
Copy your .EAR or .JAR with your EJBs to the apps folder you created, and
then run 'openejb start' in the bin directory. This will start the server
and deploy your beans. You don't get much on STDOUT, so its worth looking at
openejb.log in the logs folder.

The standalone server is only concerned with EJBs and won't serve up
webapps. As mentioned previously you can run the standalone server within
Eclipse, and I've done a video demonstrating this: http://vimeo.com/7393498


Tomcat
----------

You can integrate OpenEJB with Tomcat. This gives you the advantage that you
can deploy your EJBs along with your webapp. It sounded like you had this
working one of your previous posts. Essentially you follow the instructions
here: http://openejb.apache.org/tomcat.html which basically involves doing
the following:

copy openejb.war to Tomcat's webapps folder
goto http://localhost:8080/openejb and click the install link, and follow
the wizard through.
restart Tomcat
drop you EAR files in Tomcat's webapps folder and OpenEJB will pick them up
and deploy them. Again, have a look at the log files as STDOUT can be quiet.

You only need to deploy the openejb.war app to get this working, you don't
need the standalone server as well to get this going.

We don't have a video for this, but I could make one if that would be
useful.

Hope that helps.

Jon



On Wed, Mar 24, 2010 at 10:03 AM, hemilshah <he...@lntinfotech.com>wrote:

>
> Hi,
>
> Please brief me about using OpenEJB with Tomcat. I am confuse with two
> different paths -
>
> 1) Using OpenEJB as standalone server
> 2) Integrating openejb with Tomcat.
>
> Basically, i want to use EJBs with Tomcat so i have integrated it with
> Tomcat as specified on website, but i am unable to deploy EJB. For that it
> seems i need use OpenEJB server separately. So is it really required. Just
> integrating with Tomcat is not sufficient ? And if it is sufficient, how
> shall i deploy EJB to OpenEJB on Tomcat server ?
>
> Please clarify me about this.
>
> THanks.
> Regards,
> Hemil
> --
> View this message in context:
> http://n4.nabble.com/How-to-use-OpenEJB-with-Tomcat-tp1680307p1680307.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>

Re: How to use OpenEJB with Tomcat

Posted by hemilshah <he...@lntinfotech.com>.
This is a very simple and basic question, but i am not sure why nobody is
replying. Whereas i am seeing lots of OpenEJB experts here who can answer
this within a minute. 

Please let me know about it.
-- 
View this message in context: http://n4.nabble.com/How-to-use-OpenEJB-with-Tomcat-tp1680307p1690443.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.