2
votes

Well, this is my development environment:

  • I am using Java 1.8 and Eclipse 4.5.1 (Mars), J2EE tools and plugins installed to work with WildFly 8 as Application Server

  • I created a Java EJB project, with a simple HelloWorld stateless session bean class. It implements 2 interfaces: @Remote and/or @Local, where I defined a String getHelloWorld() stub.

  • Now, I have my client for consuming the EJB: A Dynamic Web Project with one Servlet. Inside the servlet, I can inject the ejb class using annotations, like this:

@EJB private HelloWorldLocal bean; or @EJB private HelloWorldRemote bean;

As you see, I declared the bean as HelloWorldLocal/HelloWorldRemote types. However, if I want to deploy and run my application, I need to put the EJB and Web projects into an EAR first. That allows the Servlet to know and compile the HelloWorldLocal or HelloWorldRemote bean types, by simply adding the EJB project on the Build Path as Project, or even by putting the EJB project as a Deployment Assembly directive.

I'd like to create a client outside the EAR (a remote Swing application or Remote WebSite). That means my client will have not the chance to adding the EJB project interfaces as project references in the build path as I did with the EAR. Even if I want to call the remote bean with JNDI, I need to cast the lookup() object to those types in order to use the bean methods.

The question is:

How can I get the HelloWorldRemote/HelloWorldLocal bean types from my remote client without EARs, if those interfaces are declared into an separate EJB Project? (Of course, I dont want to create a .jar with the EJB project here).

3

3 Answers

2
votes

And what about portable JNDI lookup? https://docs.oracle.com/cd/E19798-01/821-1841/girgn/index.html It should work if the EJB in the same JVM as your client.

1
votes

I'm not sure I completely understand what you're asking, and I haven't done this in years, but the normal approach for this would to to create an EJB client JAR containing only the client's bean dependencies and remote interfaces. To best accomplish this, you'll want to use a tool such as Maven to build your project which contains an EJB plugin for this. If you're not using Maven, you're going to be limited by the tooling within Eclipse, though at one point it did contain EJB client generation support. The Wildfly documentation on EJB client setup might help also, but explicitly mentions that packaging the client is out of scope.

0
votes

I'd like to share the only one solution that I found: I have to create a .jar file, with all the EJB interfaces (@Remote, @Local, and so on), and use it like referenced types on my remote clients.

This .jar would be outside any EAR. however, it needs jboss-client.jar because of the @ annotations. So, I packaged all, interfaces and jboss-client.jar, exported them to a .jar and I added this new file in my EJB and clients projects as external jar! Now I am able to use the HelloWorld* types on EJB classes implementations and @EJB client variables.

If I want a remote Web client, I've placed the EJB project with a Web Project module, into a EAR - Definitely we need an EAR. The Web module has Servlets, and the servlets handles the @EJB variables and responses. So, Outside this EAR, I just need to use URL's to the servlets and, you got it: EJB method results are reached from remote web clients.

In desktop applications with JNDI, I just put the interfaces .jar like external jar into the client project. In that way, I can cast the .lookup() to HelloWorld* types and using its methods.

  • I hope it helps.