views:

261

answers:

3

Hi guys,

I have a EJB module in remote Glassfish server and application client in my computer. I want to connect from the application client to the remote EJB.

Here is the my EJB interface:

@Remote
public interface BookEJBRemote
{
    public String getTitle();
}

Here is the my ejb:

@Stateless
public class BookEJB implements BookEJBRemote
{

    @Override
    public String getTitle()
    {
        return "Twenty Thousand Leagues Under the Sea";
    }
}

I have several questions :

  1. Can I use Dependency Injection in the remote application client to connect to the ejb? If so what can i do to achieve this. Do i need to configure in the sun-ejb-jar.xml and sun-application-client.xml? In other words, if i use Dependency Injection like @EJB BookEJBRemote book; How application client container know what ejb to be injected? Where should i specify the information?
  2. How can i run the application client? I tried to run package-appclient in the glassfish server to get appclient.jar and copy it to my computer. Then i type appclient.jar -client myAppClient.jar . It didn't work. How do i point the target server?
  3. if i cannot use Dependency Injection in the client then i guess i have to use JNDI lookup. Do i need to configure jndi name in sun-ejb-jar.xml or in the sun-application-client.xml?

No matter how i try i never manage to run application client ? Can you guys put some working example? And thank you for every advises and examples?

A: 

Check this tutorial Creating a Java Stand-Alone Client. Basically you need to

  • setup JNDI by yourself since your client can't use the containers environment.
  • Lookup the remote interface.
  • And of course include the required jar files in your classpath
stacker
The tutorial that you have cited is quite old. It is targeted to folks using NetBeans 6.1. That was released a couple years ago.
vkraemer
@vkraemer The article says it has also been tested with 6.7.1
stacker
A: 

You might take a look at this exhaustive tutorial. Although it's written for NetBeans the basic principles are the same no matter what IDE you're using.

Bozhidar Batsov
A: 

There are a number of tutorials and samples available at NetBeans.org. This tutorial discusses how to create an EJB and call its methods from an application client. The most relevant section for you is titled 'Creating an Application Client as Part of an Enterprise Application'.

vkraemer
Hey guys, I need a good tutorials. The tutorials are very basic.
Zeck