When deploying your other web components along with your EJBs make sure you don't accidently rebundle your EJBs and put them in the web components war.
The class loader will not handle that properly and you won't be able to cast your retrieved EJB interfaces anymore although the class seems to be correct...
Don't we just love EJB?! :)
Wednesday, September 13, 2006
JNDI in EJB3
Again (and every time again) after a while without EJB development I had to get used to the way the references to the EJB component interfaces get published in JNDI.
Using JBoss, it is very helpfull to go to http://:8080/jmx-console and having a look at the JNDIView MBean. It will give you a printout of the complete JNDI namespace as available.
I am yet to figure out how to access an integrated (read: in the same application) ejb from a web component. There is hardly anything about this on the web...
A standalone (or separate) client uses the global JNDI space to access objects, thus with EJB3 in JBoss, EJB references are by default being published like so:
Note that the EJB implementation name is used, not the interface name (kinda logical, though since the interface can be local or remote)
Thus when referencing the bean use for example:
and don't omit the leading "/"!
Oh, yeah and don't try to inject the EJB reference when you are in a web project: the 2.5 specification for web-apps is needed and it is not done yet! :)
If you want to play around with it anyways, here is the inclusion string:
Have a nice one,
Che
Using JBoss, it is very helpfull to go to http://
I am yet to figure out how to access an integrated (read: in the same application) ejb from a web component. There is hardly anything about this on the web...
A standalone (or separate) client uses the global JNDI space to access objects, thus with EJB3 in JBoss, EJB references are by default being published like so:
<project>/<beanclassname>/<remote|local>
Note that the EJB implementation name is used, not the interface name (kinda logical, though since the interface can be local or remote)
Thus when referencing the bean use for example:
context.lookup("/myProject/myBean/remote")
and don't omit the leading "/"!
Oh, yeah and don't try to inject the EJB reference when you are in a web project: the 2.5 specification for web-apps is needed and it is not done yet! :)
If you want to play around with it anyways, here is the inclusion string:
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
Have a nice one,
Che
Tuesday, September 12, 2006
Maven 2
I've been fighting with Maven II today and I thought I might as well share.
1) maven-ejb-plugin
Ejb3 does not require the ejb-jar.xml anymore (finally!!) and the behaviour is actually different if it is supplied one anyways.
Thus we simply do not provide one in our project.
Assuming everything else is correct and you are creating an ejb artifact you get an error about a missing ejb-jar.xml!
So you simply provide an empty one?
Nope, ejb3 uses the one you provide if there is one, and we don't want that.
Filtering for the ejb-jar.xml in maven?
No again, maven still complains about the missing file...
So let's use the <ejbVersion> tags in our maven pom together with the maven-ejb-plugin to create ejb3-compliant jar files.
No matter which version you actually use, you still get an error about a missing ejb-jar.xml.
Before you ask:
Yes, the plugin in the global repository is buggy.
Yes, to get support for ejb3 you have to compile and install it yourself.
The following should get this done:
This checks out the source (assuming you have subversion istalled) from the development trunk. I use this since I am behind a firewall and cannot use the normal checkout
CD into the subfolder and install the artifact:
With the following, maven should now accept the <ejbVersion> tags:
2) Dependencies when using ejb's
Remember that when you have a multi-module project and one of the modules is an ejb, you cannot reference the module directly in another pom:
What you get is an error complaining about a missing >version< tag in the corresponding pom.
Since you are creating an ejb you have to make sure you include it as an ejb, too:
We'll see what else I can dig up... :)
1) maven-ejb-plugin
Ejb3 does not require the ejb-jar.xml anymore (finally!!) and the behaviour is actually different if it is supplied one anyways.
Thus we simply do not provide one in our project.
Assuming everything else is correct and you are creating an ejb artifact you get an error about a missing ejb-jar.xml!
So you simply provide an empty one?
Nope, ejb3 uses the one you provide if there is one, and we don't want that.
Filtering for the ejb-jar.xml in maven?
No again, maven still complains about the missing file...
So let's use the <ejbVersion> tags in our maven pom together with the maven-ejb-plugin to create ejb3-compliant jar files.
[snip]
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.0-alpha3</version>
<configuration>
<ejbVersion>3.0</ejbVersion>
</configuration>
</plugin>
[snip]
No matter which version you actually use, you still get an error about a missing ejb-jar.xml.
Before you ask:
Yes, the plugin in the global repository is buggy.
Yes, to get support for ejb3 you have to compile and install it yourself.
The following should get this done:
This checks out the source (assuming you have subversion istalled) from the development trunk. I use this since I am behind a firewall and cannot use the normal checkout
$ svn checkout https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-ejb-plugin maven-ejb-plugin
CD into the subfolder and install the artifact:
cd maven-ejb-plugin
mvn install
With the following, maven should now accept the <ejbVersion> tags:
[snip]
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.1-SNAPSHOT</version>
<configuration>
<ejbVersion>3.0</ejbVersion>
</configuration>
</plugin>
[snip]
2) Dependencies when using ejb's
Remember that when you have a multi-module project and one of the modules is an ejb, you cannot reference the module directly in another pom:
[snip]
<dependency>
<groupId>root.project</groupId>
<artifactId>businessClasses</artifactId>
</dependency>
<dependency>
<groupId>root.project</groupId>
<artifactId>ejb</artifactId>
</dependency>
[snip]
What you get is an error complaining about a missing >version< tag in the corresponding pom.
Since you are creating an ejb you have to make sure you include it as an ejb, too:
[snip]
<dependency>
<groupId>root.project</groupId>
<artifactId>businessClasses</artifactId>
</dependency>
<dependency>
<groupId>root.project</groupId>
<artifactId>ejb</artifactId>
<version>1.0</version>
<type>ejb</type>
</dependency>
[snip]
We'll see what else I can dig up... :)
Subscribe to:
Comments (Atom)