Discussions

EJB programming & troubleshooting: How to reference ejb in another jar files?

  1. How to reference ejb in another jar files? (3 messages)

    Hi all,

    I hava two EJBs,
    One is entity bean, com.customer.OrganazitionBean, is in customer.jar.
    Another is session bean, com.util.UUIDGeneratorBean, is in util.jar.

    I'd like to call UUIDGeneratorBean in OrganazitionBean, so I insert the following in the deployment description file of customer.jar.
                <ejb-local-ref>
                    <ejb-ref-name>ejb/UUIDGeneratorBean</ejb-ref-name>
                    <ejb-ref-type>Session</ejb-ref-type>
                    <local-home>com.util.UUIDGeneratorLocalHome</local-home>
                    <local>com.util.UUIDGeneratorLocal</local>
                    <ejb-link>../util/util.jar#UUIDGeneratorBean</ejb-link>
                </ejb-local-ref>

    These jars are deployed on Weblogic7. The following exception is thrown when call UUIDGeneratorBean in OrganazitionBean.
    Exception in thread "main" javax.naming.LinkException: . Root exception is javax.naming.LinkException: .
    Root exception is javax.naming.NameNotFoundException: Unable to resolve
    'app/ejb/util.jar#UUIDGeneratorBean/local-home' Resolved: 'app/ejb' Unresolved:'util.jar#UUIDGeneratorBean'
    ; remaining name '
    util.jar#UUIDGeneratorBean/local-home'
            <
    If UUIDGeneratorBean is put into customer.jar, and the above <ejb-link> element is replaced with the following,
        <ejb-link>UUIDGeneratorBean</ejb-link>
    This program runs correctly.

    How to resolve this problem?

    Thanks.
  2. Hi,

    We had a similar problem months ago wherein the EJBs (ejb.jar) had to access classes in a different jar file (common.jar). What worked for us was to put the specify the classpath in manifest files of ejb.jar.


    The manifest looks like
    Manifest-Version: 1.0
    Class-Path: common.jar

    We had common.jar and ejb.jar in one ear file.

    Hopefully this may help or give you some idea of how to go about

    Thanks
  3. Hi,

    I looked in the spec and it gave this example,

    <enterprise-beans>
    <session>
    ...
    <ejb-name>EmployeeService</ejb-name>
    <ejb-class>com.wombat.empl.EmployeeServiceBean</ejb-class>
    ...
    <ejb-ref>
    <ejb-ref-name>ejb/EmplRecord</ejb-ref-name>
    <ejb-ref-type>Entity</ejb-ref-type>
    <home>com.wombat.empl.EmployeeRecordHome</home>
    <remote>com.wombat.empl.EmployeeRecord</remote>
    <ejb-link>EmployeeRecord</ejb-link>
    </ejb-ref>
    ...
    </session>
    ...
    <entity>
    <ejb-name>EmployeeRecord</ejb-name>
    <home>com.wombat.empl.EmployeeRecordHome</home>
    <remote>com.wombat.empl.EmployeeRecord</remote>
    ...
    </entity>
    ...
    </enterprise-beans>

    I think you need to drop "/util/util.jar#" from the ejb-link element.
  4. Actually forget my last answer as I did not read the bit in the spec before that

    "&#8226; Alternatively, to avoid the need to rename enterprise beans to have unique names within an
    entire J2EE application, the Application Assembler may use the following syntax in the
    ejb-link element of the referencing application component. The Application Assembler specifies the path name of the ejb-jar file containing the referenced enterprise bean and
    appends the ejb-name of the target bean separated from the path name by # . The path name
    is relative to the referencing application component jar file. In this manner, multiple beans with
    the same ejb-name may be uniquely identified when the Application Assembler cannot
    change ejb-names."