i'm trying to run a simple hello world kind of ejb program in eclipse. here is what i did.
i created a new enterprise application project. after that there was an option of NEW MODULE . i clicked on it and it gave me option of creating default module. i created application client module and ejb module.
IN EJB MODULE:
i have a POJI and a POJO which is a stateless bean as given below :
in the application client module i have :
so in project explorer i have an enterprise application project with 2 modules viz. ejb module and client module. i right clicked enterprise project and clicked run on server. then i exported the application client module project as export > application client jar file. i placed the jar file in the location of appclient binary of glassfish. i invoked appclient - client Testclient.jar and it gave me error that it cannot find class HelloUser.
i have included ejb moduel project in build path of application module. Please help ?
if i dont create enterprise application project but just create ejb project and put all 3 files in the single project then it runs fine.
Trying to access an EJB from a Java SE project or the ACC (Application Client Container) is always a bit tricky as you need to configure some things manually. The best way is to test from a Servlet, as you are now quite familiar with Servlets. Injection of an EJB in a Servlet doesn't need any extra configuration.
But on my client computer, I ran HelloClient, which is a standalone client, I got this error:
My conclusion: The standalone client cannot look up the address of the HelloApplication.ear file and cannot even find the HelloApplication-ejb.jar.
The remote servlet client can connect to the server over HTTP.
The magic is in the Context. For a client to access remote bean, you need to first acquire a reference to the right context. The "right" context means, you need to pass in parameters (either through jndi.properties or a HashMap or some other API that I might not be aware of) that tell your context provider to connect to the naming server that with which your bean is registered. Just doing new InitialContext() cannot give you a reference to a remote bean because it has no idea about the beans existence.
Once you acquire the right context, the URL that you have mentioned will work.
You might want to go through a good book that explains this or search for articles online.
If you are using Glassfish you can try the ACC, as I pointed out above:
The Application Client Container (ACC) includes a set of Java classes, libraries, and other files that are required for and distributed with Java client programs that execute in their own Java Virtual Machine (JVM). The ACC manages the execution of Java EE application client components (application clients), which are used to access a variety of Java EE services (such as JMS resources, EJB components, web services, security, and so on.) from a JVM outside the Oracle GlassFish Server.
The ACC communicates with the GlassFish Server using RMI-IIOP protocol and manages the details of RMI-IIOP communication using the client ORB that is bundled with it. Compared to other Java EE containers, the ACC is lightweight.
The difficulty of how to get the right Context, as Paul was pointing out, is handled by the ACC.
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!