Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
    Bookmark Topic Watch Topic
  • New Topic

Error while trying to run StatelessSessionBean

 
Rakesh Rajagopalan
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello All,

Im very new to EJB 3. I was trying to run a very simple SessionBean, and Im getting the NullPointerException. The code are as follows:

BeanClass(serverpack.BeanClass)
--------------------------------
package serverpack;

import javax.ejb.Stateless;

@Stateless
public class BeanClass implements BeanInterface {
public void message() {
System.out.println("Hello World");
}
}
Component Interface(serverpack.BeanInterface)
----------------------------------------------
package serverpack;

import javax.ejb.Remote;

@Remote
public interface BeanInterface {
void message();
}
I compiled these two classes successfully, added them to myapp.ear and deployed them in the GlassFish server.

I wrote a client class, which is as follows:
Client Class: (clientpack.BeanClient)
-------------------------------------
package clientpack;

import javax.ejb.EJB;
import serverpack.*;

public class BeanClient {
@EJB
private static BeanInterface bInterface;

public static void main(String... args) {
bInterface.message();
}
}

When I tried to run this from the command line, I got a NullPointerException. Im sure Im missing some step. Could anyone of you please guide me through this?

Kind Regards,
Rakesh.R
SCJP 6, SCWCD 5.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hih Rakesh


You must run your class with an ACC application client container, otherwise the normal java ignore the adnotations.


Radards,
M.
 
Rakesh Rajagopalan
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks for the reply. Can you please be more elaborate on the ACC? How to invoke it etc.?

Thanks,
Rakesh.R
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Rakesh,

Please do not post the same question in multiple forums http://www.coderanch.com/t/414913/EJB-JEE/java/Error-while-trying-run-StatelessSessionBean
 
    Bookmark Topic Watch Topic
  • New Topic