Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes JEE5 bean and war deployment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JEE5 bean and war deployment" Watch "JEE5 bean and war deployment" New topic
Author

JEE5 bean and war deployment

Patrick McDonogh
Ranch Hand

Joined: Oct 13, 2005
Posts: 89
Hi JavaRanchers,

I have an ebj class packaged in an ejb.jar file and a war file that has a servlet that calls the session bean in the ejb.jar file.
These are both packaged in an ear file. And i deploy the ear file to the application server which happens to be glassfish.

The servlet invokes the session bean as expected and everything works.

When i deploy the war and ejb.jar file separatelly(i.e. not in ear file) it doesnt work.

My question, is how do you deploy the ejb.jar file seraratelly to the war file and still enable the servlet in the war file get a reference to the bean.
I am using JEE5 and dependancy injection for the servlet to get a reference to the session bean. The session bean is also local not remote.

Does anyone know of a tutorial that shows how to deploy the beans separatelly from the war file.

Thanks,

Patrick
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

Patrick,
An EJB can't be deployed loose. It needs to be an EAR. It could be in a different EAR than the WAR in which case you have a remote call.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Originally posted by Jeanne Boyarsky:
Patrick,
An EJB can't be deployed loose. It needs to be an EAR. It could be in a different EAR than the WAR in which case you have a remote call.



Jeanne,
Are you sure? I have entity and stateless EJBs (3.0) deployed in JBoss, providing web services. Is this a glassfish restriction? Or is this an "accessing a WAR" restriction?

(sorry, don't know how to solve the initial problem)


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Patrick McDonogh
Ranch Hand

Joined: Oct 13, 2005
Posts: 89
Hi All,

I thought that you had to use remote when the bean is running in a different JVM, but surly the bean and war file are running on the same JVM if deployed on the same server that is not clustered with any others?

Do you know of a tutorial that shows how to deploy a war and ejbs on separated files? I know i can do it when using JNDI but would rather use dependancy injection rather than explicit JNDI bean resource location.

Thanks for the help,

Patrick
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

Ok. Let me amend my comments a bit.

As far as I know, a server is only required to support EAR and WAR deployments. While some servers do support stand alone ejb-jar deployments, they are not required to. Servers may optimize calls between apps as local calls. But again they don't have to.

I missed the fact that Patrick was using Glassfish in his original post. I haven't used Glassfish, so I wouldn't have commented if I noticed that part.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
If you deploy an EJB JAR file and a Web Application WAR file separately, they are considered two applications. This is rarely a good idea, it is almost always better to go back to what you were doing and have one application deployed as an EAR file.

If you insist on having two applications, then the EJBs must expose remote interfaces. This is because local interfaces are only possible if the client is part of the same application as the EJB.

It is irrelevant if your two applications are running in the same JVM, you still cannot use local interfaces. In order to implement local interfaces, the EJB server uses an optimisation known as pass by reference, that is making a direct method call and doing parameter passing by passing a pointer to the object. However, if you have two applications, then both will have their own classloader hierarchy. This means that any application class which has a definition in both classloaders will result in a ClassCastException error if you try to assign between applications.

The solution is for the EJB server to use the traditional pass by value between applications, even if they are within the same JVM.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JEE5 bean and war deployment
 
Similar Threads
Urgent: cannot find property file in war when packaged in ear
What's the point of an ear file?
Different ways of dependency injection
intializing log4j in a .ear file
Deploying My project in Jboss server