Jens B
Jens B

Reputation: 51

javax.naming.NameNotFoundException in external library/jar

i get a javax.naming.NameNotFoundException in my application which is deployed on a liberty server:

javax.naming.NameNotFoundException: javax.naming.NameNotFoundException: java:app/ExternalEJB/EJBBean!com.example.server.ejb.SecurityEJB
    at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext.lookup(JavaURLContext.java:355)
    at com.ibm.ws.jndi.url.contexts.javacolon.internal.JavaURLContext.lookup(JavaURLContext.java:370)
    at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)
    at javax.naming.InitialContext.lookup(InitialContext.java:428)
    at com.example.connect.server.ServiceProvider.getLocal(ServiceProvider.java:153)
    at com.example.connect.server.ServiceProvider.getLocal(ServiceProvider.java:122)
    at com.example.connect.server.ServiceProvider.getService(ServiceProvider.java:73)
    at com.example.connect.ConnectFactory.makeService(ConnectFactory.java:300)
    at com.example.connect.ConnectFactory.getService(ConnectFactory.java:280)
    at com.example.connect.ConnectFactory.getService(ConnectFactory.java:252)
    at com.example.server.ejb.EJBWrapper.getService(EJBWrapper.java:91)
    at com.example.server.ejb.EJBWrapper.find(EJBWrapper.java:1231)
    at com.example.server.bo.PersonBO.find(PersonBO.java:233)
    at de.example.framework.Wrapper.find(Wrapper.java:102)

The application structure is as follows:

Appl.ear
|
├──Module1.war (de.example.framework)
├──Module2.war
├──EJBModule.war
|
└───/lib
    ├───ExternalLib.jar (com.example.server)
    |   └── ExternalEJB (EJBBean implements SecurityEJB)
    |
    ├───ExternalLib2.jar (com.example.connect)
    |
    └───MyOwnLib.jar (de.example.service)

Now i dont know why the jdni name could not be found by the library (these two libraries work together in other projects). Any suggestions what i do wrong? If you need more informations, i try to provide them to you.

Thanks!

Edit: Since the libraries are external ones i do not have the source code, although with tool like JD i can show you how they look like:

EJBBean Declaration:

@Stateless
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@Local({SecurityEJB.class})
public class EJBBean extends BaseStatelessSessionBean implements SecurityEJB {

getLocal-method:

protected static <T> T getLocal(Class<T> cls, String jndiName) throws GenException {
    if (log.isDebugEnabled()) {
      log.debug("class        : " + cls);
      log.debug("jndi         : " + jndiName);
    } 
    Context ctx = null;
    Object local = null;
    try {
      ctx = getContext();
      if (log.isDebugEnabled())
        log.debug("context      : " + ctx); 
      local = ctx.lookup(jndiName); <--- line 153
      if (log.isDebugEnabled()) {
        log.debug("local        : " + local);
        log.debug(" class       : " + local.getClass().getName());
        log.debug(" class loader: " + local.getClass().getClassLoader());
      } 
      return (T)local;
    } catch (NamingException ex) {
      throw new GenException(ex);
    } 
  }

the SecurityEJB Interface:

public interface SecurityEJB extends ICompressible {
  public static final String JNDI_NAME = "java:app/ExternalEJB/EJBBean!" + SecurityEJB.class
    .getName();

features in server.xml:

<featureManager>
    <feature>javaee-8.0</feature>
    <feature>localConnector-1.0</feature>
    <feature>ejbRemote-3.2</feature>
    <feature>ldapRegistry-3.0</feature>
    <feature>transportSecurity-1.0</feature>
</featureManager>

Upvotes: 0

Views: 847

Answers (1)

Tracy
Tracy

Reputation: 1073

Per the Java EE Platform Specification (Deploying a Java EE Application), a module is only considered an EJB module if it is not in the lib directory and contains either an META-INF/ejb-jar.xml file or an EJB component defining annotation, such as @Stateless.

In this example, since the EJBBean class is in lib/ExternalLib.jar, the @Stateless annotation will be ignored. The ExternalLib.jar JAR file is not considered to be an EJB module since it is in the lib directory.

ExternalLib.jar either needs to be moved out of the lib directory, or one of the other EJB or WAR modules needs to contain an ejb-jar.xml file that declares EJBBean to be an EJB. All classes in the lib directory may be referenced by EJB and WAR modules, so it is acceptable to declare a class from a lib module as an EJB in the ejb-jar.xml file of a WAR or EJB module. Note that the java: lookup would use the module name where the ejb-jar.xml file is located; never the name of a JAR in the lib directory.

Upvotes: 2

Related Questions