title: Using EJBs from a different JAR
body: <p>I'm developing a JAX-WS WebService in JDeveloper 11.1.1.4 that should use EJBs from a JAR previously deployed to a WebLogic server. Both the WebService project and the EJB project are my own code, but I'd like to deploy them separately. For now I'm experimenting with the setup.</p>
  
  <p>In the <strong>ExampleEJB</strong> project I have a bean ExampleBean that implements a remote interface Example.</p>
  
  <pre><code>@Remote
  public interface Example {
      public String doRemoteStuff();
  }
  
  @Stateless(name = "Example", mappedName = "ExampleApplication-ExampleEJB-Example")
  public class ExampleBean implements Example {
      public String doRemoteStuff() {
          return "did remote stuff";
      }
  }
  </code></pre>
  
  <p>In that project, I have two deploy descriptors (ejb-jar.xml and weblogic-ejb-jar.xml):</p>
  
  <p><strong>ejb-jar.xml</strong></p>
  
  <pre><code>&lt;?xml version = '1.0' encoding = 'UTF-8'?&gt;
  &lt;ejb-jar 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"
           version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"&gt;
    &lt;enterprise-beans&gt;
      &lt;session&gt;
        &lt;ejb-name&gt;Example&lt;/ejb-name&gt;
      &lt;/session&gt;
    &lt;/enterprise-beans&gt;
  &lt;/ejb-jar&gt;
  </code></pre>
  
  <p><strong>weblogic-ejb-jar.xml</strong></p>
  
  <pre><code>&lt;?xml version = '1.0' encoding = 'UTF-8'?&gt;
  &lt;weblogic-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd"
                    xmlns="http://www.bea.com/ns/weblogic/weblogic-ejb-jar"&gt;
    &lt;weblogic-enterprise-bean&gt;
      &lt;ejb-name&gt;Example&lt;/ejb-name&gt;
      &lt;stateless-session-descriptor/&gt;
    &lt;/weblogic-enterprise-bean&gt;                  
  &lt;/weblogic-ejb-jar&gt;
  </code></pre>
  
  <p>Additionaly, I've created an EJB JAR deployment profile named example-ejb.jar and managed to deploy it to the server.</p>
  
  <p>In the <strong>ExampleWS</strong> project I have an ExampleWebService:</p>
  
  <pre><code>@WebService(serviceName = "ExampleWebService")
  public class ExampleWebService {
  
      @EJB
      Example example;
  
      public String doStuff() {
          return example.doRemoteStuff();
      }
  }
  </code></pre>
  
  <p>I added the ExampleEJB project dependency to this project (so it would compile). The only XML I have in this project is the web.xml used to describe the servlet. Also, I have the WebServices WAR file created automatically by jDeveloper when creating a WebService. Lastly, I created an EAR deployment profile named example-ws that only includes the WebServices WAR file in it's application assembly.</p>
  
  <p>What do I need to do for this to work? Also, what would the procedure be if the ExampleEJB project was referenced from another project (say, AdditionalExampleEJB) that has additional beans that use ExampleBean? How would I reference the ExampleBean from there?</p>
  
  <p>Thank you VERY MUCH for any help you can give me!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I've managed to reference the EJB from the WebService!</p>
  
  <p>In the <strong>ExampleEJB</strong> project I modified the weblogic-ejb-jar.xml and now it looks like this:</p>
  
  <p><strong>weblogic-ejb-jar.xml</strong></p>
  
  <pre><code>&lt;?xml version = '1.0' encoding = 'UTF-8'?&gt;
  &lt;weblogic-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd"
                    xmlns="http://www.bea.com/ns/weblogic/weblogic-ejb-jar"&gt;
    &lt;weblogic-enterprise-bean&gt;
      &lt;ejb-name&gt;Example&lt;/ejb-name&gt;
      &lt;stateless-session-descriptor&gt;
        &lt;pool&gt;
          &lt;max-beans-in-free-pool&gt;10&lt;/max-beans-in-free-pool&gt;
          &lt;initial-beans-in-free-pool&gt;3&lt;/initial-beans-in-free-pool&gt;
        &lt;/pool&gt;
        &lt;business-interface-jndi-name-map&gt;
          &lt;business-remote&gt;hr.example.Example&lt;/business-remote&gt;
          &lt;jndi-name&gt;ejb/example-ejb/Example&lt;/jndi-name&gt;
        &lt;/business-interface-jndi-name-map&gt;
      &lt;/stateless-session-descriptor&gt;
    &lt;/weblogic-enterprise-bean&gt;                  
  &lt;/weblogic-ejb-jar&gt;
  </code></pre>
  
  <p>In the <strong>ExampleWS</strong> project I added a deployment descriptor weblogic.xml that looks like this:</p>
  
  <p><strong>weblogic.xml</strong></p>
  
  <pre><code>&lt;?xml version = '1.0' encoding = 'UTF-8'?&gt;
  &lt;weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd"
                    xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app"&gt;
    &lt;ejb-reference-description&gt;
      &lt;ejb-ref-name&gt;ExampleReference&lt;/ejb-ref-name&gt;
      &lt;jndi-name&gt;ejb/example-ejb/Example&lt;/jndi-name&gt;
    &lt;/ejb-reference-description&gt;
  &lt;/weblogic-web-app&gt;
  </code></pre>
  
  <p>Note that the <em>ExampleReference</em> value and <em>ejb/example-ejb/Example</em> value are something I decided to enter - I think they is more or less a developer's choice.</p>
  
  <p>Also, I referenced the EJB in my WebService using the <em>ExampleReference</em> value, so my ExampleWebService looks like this:</p>
  
  <p><strong>ExampleWebService</strong></p>
  
  <pre><code>@WebService(serviceName = "ExampleWebService")
  public class ExampleWebService {
      @EJB(
        name="ExampleReference"
      )
      Example example;
  
      public String doStuff() {
          return example.doRemoteStuff();
      }
  }
  </code></pre>
  
  <p>Lastly, in the deployment profile of ExampleWS (the WebServices.war) I added the dependency contributor and checked the interface Example.class element (<strong>NOT</strong> the ExampleBean.java that has the implementation).</p>
  
  <p>Now, how would this work if the Example bean was referenced from another EJB project (not a WebService)?</p>