• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JEE5 bean and war deployment

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic