3 Replies Latest reply: Feb 23, 2012 9:13 AM by Mark Paluch RSS

Accessing a deployed EJB from a war in the same AS 7 instance

lholmquist Newbie

I'm sort of new to the whole EJB model.  I'm using as7.1.0.FINAL as my app server

 

I have a web app where i am using some @Stateless EJB's that are deployed in the war with the rest of my app and i'm using @Inject to access them. 

this works fine and i'm comfortable with this.

 

There is some functionality that i have that i would like other apps that are running on the same instance of AS 7 to access.

 

I've created a simple EJB(hello world) and deployed it. 

 

code:

 

public interface IHelloWorld {

 

 

    String sayHi(String value);

 

 

}

 

 

@Stateless

public class HelloWorld implements IHelloWorld

{

    @Override

    public String sayHi(String value) {

        return value; 

    }

}

 

 

 

 

console:

11:01:53,172 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named HelloWorld in deployment unit deployment "WebLogger.jar" are as follows:

 

 

          java:global/WebLogger/HelloWorld!mlmic.IHelloWorld

          java:app/WebLogger/HelloWorld!mlmic.IHelloWorld

          java:module/HelloWorld!mlmic.IHelloWorld

          java:global/WebLogger/HelloWorld

          java:app/WebLogger/HelloWorld

          java:module/HelloWorld

 

 

In my war, i am trying to use @Inject IHelloWorld helloWorld;  to get access to this EJB

 

I'm using maven, so i added the dependecy for the other project so the war will compile.

 

this is were i'm not sure what to do,  i set the scope of the dependecy in the war to provided so i don't get a copy of the ejb jar in the web-inf/lib .  however if i do this then the war won't deplot because of class loading errors.

 

All the quickstarts i've looked at are either deploying the EJB inside a war or ear.  The accessing a remote ejb from a client quickstart might work but i thought that i could access an EJB with @Inject if i was running on the same jvm

 

My question is, what is the best way to do this.