EJB 3.1 application deployed as WAR-only: how about ejb-jar.xml?

I have a JavaEE6 application consisting of web content and EJB and deployed as WAR-only (using EJB3.1). Building based on Maven. I just read about the new opportunity to order module initialization in Java EE 6 here , which I also need for my application. Also, I would like to be able to define some EJB properties in XML.

Since the example is deployed as an EAR project, the order is defined in application.xml. But the project deployed to WAR does not have application.xml. Now I wonder, where can I determine such information? Or can you somehow use application.xml in a WAR-deployed application?

EDIT:

Unfortunately, I did not read the example of the order module, at the first moment I thought that this concerns the order in which EJBs are loaded in my application. Of course, there is only one module in my WAR application, so ordering does not make sense.

Ok, but since I'm on it, one big question remains (also changed the name of the question to reflect the change): What about ejb-jar.xml? Can I somehow define the material about my EJBs in XML (how is it useful for some settings to avoid recompiling)?

+7
java java-ee java-ee-6
source share
2 answers

In short, this is not possible with WAR-based deployments.

The Java EE 6 module initialization function is designed to initialize various application modules in a specific order. When you have a WAR-based EJB application, you no longer have separate modules for your EJB and web application. There is only one module - the web application module in a WAR-based deployment.

Therefore, if you need to perform the same function as the module initialization order proposed in Java EE 6, you need to do one of the following:

  • Separate the EJB into a separate module and use the EAR-based deployment.
  • This is more or less a hoax, as was done in Java EE 5, and you would like to avoid it. You might want to code in logic to make sure single EJBs are created (assuming that this involves using singletones in your application) before they are used in the code.

Location of ejb-jar.xml in the WAR file

The EJB 3.1 specification (in the packaging chapter) solves the problem of the location of the ejb-jar.xml file when deployed to WAR:

In the .war file, the deployment descriptor is stored with the name WEB-INF / EJB-jar.xml.

PS: I have not tried this deployment style yet. YMMV.

+9
source share

An EJB side note in handling .wars and ejb-jar.xml. As already mentioned, this is WEB-INF / ejb-jar.xml, but also note that this location is only , even if in WEB-INF / lib / - there are standard ejbs blocks - through the standard rules any META-INF / ejb files -jar.xml are ignored.

The expert group has been pretty split into this, so if you have a preference, it's not too late to send feedback to the list of EJB 3.1 expert groups for consideration in EJB.next.

My vote was to allow individual banks to have META-INF / ejb-jar.xml files, as these banks can now have persistence.xmls, beans.xmls, web fragments, etc. The big problem for me was that it contradicts the Embedded EJB Container API, which supports the EAR class path, which allows several banks / modules, each of which can contain the META-INF / ejb-jar.xml file. As a result, if you use the built-in API to test an ejb application with several jar, which is compiled into a single .war file, your task is to merge any ejb-jar.xml data that you have into one ejb -jar.xml for webapp. Kind of pain for users.

+5
source share

All Articles