0

Disclaimer: I'm new to Java EE and have never worked with EJBs until recently so forgive me if I use some terms or expressions wrongly.

I'm working on a simple application using Java EE and EJB. I need to access an EJB while the application is running. If I have understood correctly you declare beans like this:

@EJB
private ProgressBeanRemote progressBean;

However if I try to access the bean inside the application like this:

System.out.println(progressBean.getSomeValue());

I get the following error message:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at project.name.TestClass.java:10

Now to me it seems the JVM sees the progressBean as a field with no instance and therefore throws a nullpointerexception. However it is not possible (and wouldn't make sense) to create a new object of the bean since it's a really a remote. Other than this I have not much to go on. So my question is: How can I access beans from inside a running JavaFX application?

NOTE: I have tested my app as a regular Java program (no GUI) and then it works. Also I use JDK 1.8 and Java EE 7.

EDIT: I am aware of what a NullPointerException is, I just don't understand why the remote is not recognized when I try to access it from JavaFX specifically.

Sifu
  • 153
  • 1
  • 17
  • 2
    Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Yassin Hajaj Nov 23 '15 at 22:01
  • 2
    I disagree with the duplicate call. This is specifically why EJBs are not being loaded correctly from inside a JavaFX application. – Archimedes Trajano Nov 23 '15 at 22:07

1 Answers1

1

EJBs need to be run in a container or an Application Client environment. For your scenario it sounds like the Application Client project is what you need. Generally this client is specific to the application server because the transports are usually vendor specific, though the code should be the same for any app server following the standards.

My recommendation though is to use a more standard API such as SOAP using JAX-WS or a REST API like JAX-RS which you can get implementations that do not require anything vendor specific.

Personally, I would recommend JAX-WS because it is more "strict" with what you can send and receive.

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265