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.
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.
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.
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
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop