5 Replies Latest reply on Mar 14, 2008 2:52 AM by caili314

    ejb-jar.xml a clear definition for EJB3

    Alessandro Ilardo Newbie

      Hi there,
      I'm facing a problem which is probably quite common with newbie like me. There a lot of informations and tutorials on the net, but they're quite different between eachother. So in the end we are just confused and we are not sure about we are following the good procedure.

      I'm ok with Persistence and EJB3 annotations (for the moment), but I'm stuck with the configuration files.

      First of all, with the annotations, do we still need the ejb-jax.xml? And if yes, how should it look like, at least the minimum tags required by JBoss 4.1

      Same question for the jboss.xml.

      I'm trying to deploy an EJB Module which implements Hibenate and EJB3, is it correct rename the package as .ejb3 instead of .jar?

      I hope that someone with more experience then me help me in keep this thread active as I think to not be the only person facing these issues.

      Thanks in advance

        • 1. Re: ejb-jar.xml a clear definition for EJB3
          Giancarlo Cadei Newbie

          Hello, I'm a newbie with application servers and ejb3 in particular (so maybe you fall from the pan in the brace - as we say in italian) but with my search on internet and with a lot of patient I've concluded that what you need to deploy an ejb3 is.
          Suppose you want to deploy a jar with a session bean that use an entity (POJO) bean. Who use the bean is another jar into the same application (ear)
          1) the bean jar need an ejb-jar.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">


          2) it need also a jboss.xml:
          <?xml version="1.0" encoding="UTF-8"?>


          3) For the entity is required a persistence.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
          <persistence-unit name="uns-ejbPU" transaction-type="JTA">


          4) I've also used a jndi.properties

          The Session bean implements the Local and the Remote interface.

          <<In the mouth of the loop>> (reply is .... <>)


          • 2. Re: ejb-jar.xml a clear definition for EJB3
            Oskar Carlstedt Novice


            No, in general you don't need the ejb-jar.xml. You can include the ejb-jar.xml file if you intend to override settings from given annotations. But in generel, you don't need it.

            What you need to do is:
            Create a JAR-file with the ejb:s you want to deploy. This file must also include a META-INF/persistence.xml file where you ponit out the datasource you wan't to use. Here is an example:

            <persistence xmlns="http://java.sun.com/xml/ns/persistence"
             <persistence-unit name="my-ejbs">
             <property name="hibernate.hbm2ddl.auto" value="create-drop" />
             <property name="show_sql" value="true" />
             <property name="dialect"
             value="org.hibernate.dialect.MySQLDialect" />

            The structure of the final jar file containing the ejb:s is something like:

            Then you need to create an ear-file. This is not a must, but you get better structure if you deploy your ejbs in an ear file. You still need to specify the META-INF/application.xml file. Here is an example:
            <?xml version="1.0" encoding="UTF-8"?>
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
             <description>my application description</description>
             Point out the ejb jar files as ejb modules
             Point out the war files as web modules

            A good idea is also to bundle the dependent jar files in the ear file. Place them in the lib folder of the ear file. In the META-INF folder you create a jboss-app.xml file where you tell jboss to use the libs you provide in the ear file. Note that if you do this way and also include a war file in the ear - then make sure you don't have any WEB-INF/libs/... in the war file. Here is an example:
            <!DOCTYPE jboss-app
             PUBLIC "-//JBoss//DTD J2EE Application 1.4//EN"

            So finally, this is the structure of the ear file:

            Kind regards

            • 3. Re: ejb-jar.xml a clear definition for EJB3
              Oskar Carlstedt Novice


              One more thing I forgot. If you don't provide the ejb-jar.xml file, JBoss will deploy your ejbs as:

              <NAME-OF-EAR-FILE>/<BEAN-CLASS-NAME>/Local or

              In the example above you will get something like:
              /my-service/MyBean/Local or /my-service/MyBean/

              Sorry for using the word "service" here. I did'd som web services and called them ...-service. That's why the service extension of the ear file's name.


              • 4. Re: ejb-jar.xml a clear definition for EJB3
                Hao Huang Newbie

                Is there any 'official' manual or reference docu available which specifies those xml configuration(persistence.xml, application.xml, ejb-jar.xml and also jboss-app.xml and jboss-web.xml) files?

                What kind of editor you guys use to edit those files?

                Thx in advance!

                • 5. Re: ejb-jar.xml a clear definition for EJB3

                  Overriding metadata through XML, which file should the following contents be put?

                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"