Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JEE5 bean and war deployment

 
Patrick McDonogh
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Patrick McDonogh
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic