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

    ejb-jar.xml a clear definition for EJB3

    sandrocchio_0.1

      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

          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">
          <display-name>uns-bean</display-name>
          <enterprise-beans>

          <ejb-name>UniqueNumberBean</ejb-name>

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

          <ejb-name>UniqueNumberBean</ejb-name>
          <jndi-name>UniqueNumberBean</jndi-name>

          </enterprise-beans>
          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">
          org.hibernate.ejb.HibernatePersistence
          <jta-data-source>java:OracleDS</jta-data-source>
          eu.efsa.docreg.uns.beans.PendingNumber
          <exclude-unlisted-classes>true</exclude-unlisted-classes>


          </persistence-unit>

          4) I've also used a jndi.properties
          java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
          java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
          java.naming.provider.url=localhost:1099

          The Session bean implements the Local and the Remote interface.

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

          Regards
          Giancarlo

          • 2. Re: ejb-jar.xml a clear definition for EJB3
            oskar.carlstedt

            Hello!

            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"
             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"
             version="1.0">
             <persistence-unit name="my-ejbs">
             <jta-data-source>
             java:/my-ejbs-DS
             </jta-data-source>
             <properties>
             <!--
             <property name="hibernate.hbm2ddl.auto" value="create-drop" />
             -->
             <property name="show_sql" value="true" />
             <property name="dialect"
             value="org.hibernate.dialect.MySQLDialect" />
             </properties>
             </persistence-unit>
            </persistence>
            


            The structure of the final jar file containing the ejb:s is something like:
            /my-ejbs.jar
             /META-INF
             MANIFEST.MF
             persistence.xml
             /my
             /example
             /bean
             MyBean.class
             ...
            


            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"?>
            <application
             xmlns="http://java.sun.com/xml/ns/j2ee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
             version="1.4">
             <description>my application description</description>
             <display-name>my-application</display-name>
            
             <!--
             Point out the ejb jar files as ejb modules
             -->
             <module>
             <ejb>my-ejbs.jar</ejb>
             </module>
            
             <!--
             Point out the war files as web modules
             -->
             <module>
             <web>
             <web-uri>my-service-jaxws-web.war</web-uri>
             <context-root>/my-service-jaxws-web</context-root>
             </web>
             </module>
            </application>
            


            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"
             "http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd">
            <jboss-app>
             <loader-repository>my-ejbs:app=ejb3</loader-repository>
            </jboss-app>
            


            So finally, this is the structure of the ear file:
            my-service.ear
             /my-ejbs.jar
             /lib
             dependency_jar_A.jar
             dependency_jar_B.jar
             ...
             /META-INF
             MANIFEST.MF
             application.xml
             jboss-app.xml
            



            Kind regards
            Oskar


            • 3. Re: ejb-jar.xml a clear definition for EJB3
              oskar.carlstedt

              Oooppss..

              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
              <NAME-OF-EAR-FILE>/<BEAN-CLASS-NAME>/Remote.

              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.

              //Oskar

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

                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?

                  <entity-mappings
                   xmlns="http://java.sun.com/xml/ns/persistence/orm"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
                   version="1.0">
                  
                   <persistence-unit-metadata>
                   <xml-mapping-metadata-complete/>
                   <persistence-unit-defaults>
                   <schema>myschema</schema>
                   <catalog>mycatalog</catalog>
                   <cascade-persist/>
                   </persistence-unit-defaults>
                   </persistence-unit-metadata>