Select Your Language

Infrastructure and Management

Cloud Computing

Storage

Runtimes

Integration and Automation

  • Comments
  • JNDI Lookup to java:comp/env results in 'javax.naming.NameNotFoundException: java:comp/env'

    Posted on

    Hi,

    we use a third party application which can be enabled to use datasources of the application server for database access.
    With JBoss 5.x the application worked fine using datasources which were configured within the JBoss instance.

    After migration to JBoss EAP 6.2 EAP the application fails when trying to use a datasource.
    The logfile of the application shows then the following entry:

    16:50:31,856 INFO  [dbRequest] (pool-4-thread-1) isPooled: true
    16:50:31,858 ERROR [dbRequest] (pool-4-thread-1) javax.naming.NameNotFoundException: java:comp/env
        at org.jboss.as.naming.InitialContext.findContext(InitialContext.java:198)
        at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:118)
        at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:183)
        at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)
        at javax.naming.InitialContext.lookup(InitialContext.java:411)
        at com.genesyslab.studio.backendlogic.db.CVDBBackendHandler.getConnection(Unknown Source)
        at com.genesyslab.studio.backendlogic.db.CVDBBackendHandler.access$100(Unknown Source)
        at com.genesyslab.studio.backendlogic.db.CVDBBackendHandler$1.call(Unknown Source)
        at com.genesyslab.studio.backendlogic.db.CVDBBackendHandler$1.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:744)
    

    When decompling the library they use for opening a datasource connection we found the following code:

                    InitialContext initialContext = new InitialContext();
                    Context context = (Context)initialContext.lookup("java:comp/env");
                    DataSource dataSource = (DataSource)context.lookup(string5);
                    logger.info((Object)"CVDBBackendHandler.getConnection() out");
                    return dataSource.getConnection();
    

    I could veryfy with a simple EAR that the following line causes "NameNotFoundException" in JBoss EAP 6.2 GA and JBoss 6.4 GA:

    Context context = (Context)initialContext.lookup("java:comp/env");
    

    We opened a ticket against the vendor, but he insists that the JNDI context "java:comp/env" still exists in 6.2 and 6.4 and rejected the ticket.
    The interesting part is, that all RH EAP documentation we found, this JNDI context is still referenced for EAP 6.x.

    So here are our questions:
    a) if "java:comp/env" is still available, why get I a "NameNotFoundException" when I use 'Context context = (Context)initialContext.lookup("java:comp/env");'?
    Do I have to change somethin in the "standalone.xml"?

    b) if "java:comp/env" isn't supported any longer, where can I find an official statment, that it isn't any longer?

    Best Regards
    Peter

    by

    points

    Responses

    Red Hat LinkedIn YouTube Facebook X, formerly Twitter

    Quick Links

    Help

    Site Info

    Related Sites

    © 2026 Red Hat