-1
1   InitialContext initialContext = new InitialContext();
2   EJBHome ejbHome = (EJBHome) initialContext.lookup(jndiLocation);
3   Class  ejbHomeClass = ejbHome.getClass();
4   Method createMethod = ejbHomeClass.getMethod("create", new Class[] { });

The exception is thrown from line 2 when the code executes the initial context lookup and stores it in an EJBHome object.

I have seen this issue several times and tried several solutions such as including the j2ee.jar in the classpath and manifest. However, their solutions might not apply to this issue since it occurs on a thread.

Loren
  • 1,260
  • 5
  • 16
  • 23
  • Is this a standalone java client, an "in remote server" client or an "in same server client"? – Steve C May 15 '17 at 12:14
  • It's a same server client. – Loren May 16 '17 at 05:35
  • You need to get rid of every jar that contains any Java EE APIs or implementations from your deployment(s), especially j2ee.jar. What kind of code is spawning the thread? An EJB or a servlet? – Steve C May 16 '17 at 05:43
  • It's an EJB. If I get rid of the j2ee.jar where will the code retrieve the reference to the EJBHome class? – Loren May 16 '17 at 06:22
  • The server provides it. What server (and version) is it running in? – Steve C May 16 '17 at 06:28
  • I see, I'm currently using IBM Websphere 8.5. Are you referring to files inside the AppServer lib folder? Btw, I removed the reference of the j2ee.jar in my project and it generated an error in the class that extends the EJBHome class. – Loren May 16 '17 at 06:51
  • At compile time or runtime? What is the error? – Steve C May 16 '17 at 06:57
  • At compile time and the error is "The import javax.ejb cannot be resolved" – Loren May 16 '17 at 07:07
  • You need to compile with that jar (or preferably the newer [javaee-api.jar](http://search.maven.org/remotecontent?filepath=javax/javaee-api/7.0/javaee-api-7.0.jar), but you must exclude it from the assembly of your deployments. – Steve C May 16 '17 at 07:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/144315/discussion-between-loren-and-steve-c). – Loren May 16 '17 at 07:12

1 Answers1

0

You should not use user-defined threads with EJB.

The EJB container is responsible for managing system-related functionality such as security, threading, resource pooling, and so on. In order to control these facets of component operation, the container places certain restrictions on the components it manages.

See http://www.oracle.com/technetwork/java/restrictions-142267.html

Mike Adamenko
  • 2,944
  • 1
  • 15
  • 28