title: How to inject an EJB from another ejb file in a same application?
body: <p>I am learning JavaEE 7 recently. I have a problem when I try to inject an ejb from a separate jar file.</p>
  
  <p>My code is like </p>
  
  <pre><code>@Stateless
  public class HelloService {
  
      public String hello(String name) {
          return "Hello " + name;
      }
  
  }
  </code></pre>
  
  <p>The HelloService is in independed project and I have published it into the glassfish4 server as ejb file.</p>
  
  <p>Then I have JSF project, right now I only have one backing bean</p>
  
  <pre><code>@Model
  public class IndexBean {
  
      @Inject
      private HelloService helloService;
  
      public String getName() {
          return helloService.hello("World");
      }
  }
  </code></pre>
  
  <p>After build the JSF project. I published it to the same glassfish4 server. But in my JSF project, it can't inject HelloService bean from other jar file.</p>
  
  <p>I tried to add @Remote on the HelloService class, it's still not inject-able.</p>
  
  <p>I have 3 pom files.</p>
  
  <p>Parent Project:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;org.chris.sample&lt;/groupId&gt;
      &lt;artifactId&gt;javaee7-samples&lt;/artifactId&gt;
      &lt;version&gt;1.0.0&lt;/version&gt;
      &lt;packaging&gt;pom&lt;/packaging&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax&lt;/groupId&gt;
              &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
              &lt;version&gt;7.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
              &lt;artifactId&gt;derby&lt;/artifactId&gt;
              &lt;version&gt;10.10.1.1&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.11&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
  
      &lt;/build&gt;
      &lt;modules&gt;
          &lt;module&gt;javaee7-jsf&lt;/module&gt;
          &lt;module&gt;javaee7-ejb&lt;/module&gt;
      &lt;/modules&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>JSF Project:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.chris.sample&lt;/groupId&gt;
          &lt;artifactId&gt;javaee7-samples&lt;/artifactId&gt;
          &lt;version&gt;1.0.0&lt;/version&gt;
      &lt;/parent&gt;
      &lt;artifactId&gt;javaee7-jsf&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.chris.sample&lt;/groupId&gt;
              &lt;artifactId&gt;javaee7-ejb&lt;/artifactId&gt;
              &lt;type&gt;jar&lt;/type&gt;
              &lt;version&gt;1.0.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.4&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>EJB Project:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;parent&gt;
      &lt;groupId&gt;org.chris.sample&lt;/groupId&gt;
      &lt;artifactId&gt;javaee7-samples&lt;/artifactId&gt;
      &lt;version&gt;1.0.0&lt;/version&gt;
    &lt;/parent&gt;
    &lt;artifactId&gt;javaee7-ejb&lt;/artifactId&gt;
    &lt;packaging&gt;ejb&lt;/packaging&gt;
  &lt;/project&gt;
  </code></pre>