0 Replies Latest reply on Oct 27, 2004 4:39 AM by Norman Fung

    EJB Deployment Decriptors

    Norman Fung Newbie

      I'm newbie in J2EE, having read a bunch of stuff I'm still in the wood. Please bear with me.

      Here's an example descriptor:

      <ejb-jar>
       <enterprise-beans>
       <session>
       <ejb-name>beanA</ejb-name>
       ...
       <resource-ref>
       <res-ref-name>jdbc/dbname</res-ref-name>
       <jndi-name>jdbc/dbname</jndi-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
       <res-sharing-scope>Shareable</res-sharing-scope>
       </resource-ref>
      
       <env-entry>
       <env-entry-name>Var1</env-entry-name>
       <env-entry-type>java.lang.String</env-entry-type>
       <env-entry-value>Some value</env-entry-value>
       </env-entry>
       ...
      
      
       <ejb-ref>
       <ejb-ref-name>ejb/ses1</ejb-ref-name> QUESTION 1: ejb/ses1??? Is it "SS1" JNDI name? Why isn't JNDI name declared in "ejb-jar.xml"??
       <ejb-ref-type>session</ejb-ref-type>
       <home>tests.SS1Home</home>
       <remote>tests.SS1</remote>
       </ejb-ref>
      
       <ejb-local-ref>
       <ejb-ref-name>ejb/locses1</ejb-ref-name>
       <ejb-ref-type>session</ejb-ref-type>
       <local-home>tests.LocalSS1Home</local-home>
       <local>tests.LocalSS1</local>
       </ejb-local-ref>
       ...
      
       </session>
      
       <session>
       <ejb-name>SS1</ejb-name>
       <home>tests.SS1Home</home>
       <local-home>tests.LocalSS1Home</local-home>
       <remote>tests.SS1</remote>
       <local>tests.LocalSS1</local>
       <ejb-class>tests.SS1Bean</ejb-class>
       ...
       </session>
       ...
       </enterprise-beans>
      </ejb-jar>
      


      QUESTION 2. What's the purpose of "ejb-ref", "ejb-local-ref" in EJB deployment descriptor? Is it that if one EJB (ejb/beanA) depends on another, say (ejb/ses1) (by virtue of having the dependency declared in deployment descriptor) - deployment of "ejb/beanA" would fail if "ejb/ses1" was not deployed on the target server? That DEPLOYMENT of an EJB (depending on a particular resource) would FAIL if that resource it depends on is absent on the destination server? Is this the only purpose?

      QUESTION 3. Should I specify JNDI names for <ejb-name> tag?

      QUESTION 4. Is "fully qualified" JNDI name (for the above bean):
      JNDI name = "java:comp/" + <ejb-name>
      example: "java:comp/ejb/beanA"

      OR just:
      JNDI name = "java:" + <ejb-name>
      example: "java:ejb/beanA"

      Is this true for all application servers? JBoss? Or does it depends on "ejb-name" to "jndi-name" mapping as specified in "jboss.xml" (see below)

      QUESTION 5. For JBoss EJB's, "ejb-name" to "jndi-name" mapping is done in "jboss.xml":

      <jboss>
       <enterprise-beans>
       <entity>
       <ejb-name>beanB</ejb-name>
       <local-jndi-name>ejb/beanB</local-jndi-name>
       </entity>
       <session>
       <ejb-name>beanA</ejb-name>
       <jndi-name>ejb/beanA</jndi-name>
       </session>
       </enterprise-beans>
      </jboss>
      


      Does it mean if "jndi-name" is NOT specified, then by default, "jndi-name" of the bean would equal "ejb-name"?

      "java:com/" + <ebj-name>

      EQUALS:

      "java:com/" + <jndi-name>

      EQUALS:

      "java:com/beanA"


      QUESTION 6. Why "java:comp/"? What's that for? Is it:
      a. "java:comp/"
      b. "java:comp"
      c. "java:"

      I think I've seen different versions, getting really confused.

      QUESTION 7. For environment variables, it seems:

      JNDI name="java:comp/env" +<env-entry-name>

      In this case,
      "java:comp/env/Var1"

      Is this true for all servers?

      QUESTION 8. For data sources (JBoss), you need to put "mysql-ds.xml" under "Deploy" folder:

      <datasources>
       <local-tx-datasource>
       <jndi-name>jdbc/exampleDS</jndi-name> <connection-url>jdbc:mysql://127.0.0.1:3306/DBName</connection-url>
       <driver-class>...</driver-class>
       <user-name>xxx</user-name>
       <password>xxx</password>
       </local-tx-datasource>
      </datasources>
      


      6a. I dont understand why we need to append "java:" in context.lookup:

      context=new InitialContext();
      dataSource=(DataSource) context.lookup("java:jdbc/exampleDS");
      


      6b. Can we rename the file name "mysql-ds.xml" to anything we like as long as it remains in "Deploy" folder? (Tested this on JBoss)

      Thanks.