One very simple solution which solves my problem.
Change the schema reference from
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app></web-app>
to this
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
version="2.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
// ...
// your all content goes here
</web-app>
Well, this question is quite old, and I see that there's no accepted answer yet, so.
Here is what really happens:
- Your code executes a JNDI lookup to
java:comp/env/DB2_DB
.
- WebSphere uses the WAS-proprietary deployment descriptor (
ibm-web-bnd.xml
) to "translate" the application binding DB2_DB
into a real name in the WebSphere JNDI tree (jdbc/DB2DB
).
- WebSphere looks up
jdbc/DB2DB
and returning it to the caller.
You are getting a NameNotFoundException
on the first lookup - the lookup of java:comp/env/DB2_DB
. The problem is not with finding jdbc/DB2DB
; it's with finding DB2_DB
inside your component's environment.
Your deployment descriptor looks OK to me, so I'm guessing that the reason for your problem is this:
Context aContext = new InitialContext(settings);
You are constructing an InitialContext
instance by providing a Hashtable
. The Hashtable
is often useful when you need to provide special parameters for the construction, but you must know when to use it and when to avoid it. Code that runs inside a JavaEE container and needs simple access to the container's JNDI tree rarely, if ever, should provide any Hashtable
to the InitialContext
constructor.
I wouldn't be surprised if those settings
that you're passing into InitialContext
contain, for example, a PROVIDER_URL
key instructing the lookup to happen on some distant foreign JNDI tree.
So, I would start by scrapping that parameter:
Context aContext = new InitialContext();
And then give it another shot.
If that still fails, use WebSphere's dumpNamespace
utility to get a clear picture of WebSphere's JNDI tree.
Best Answer
If you are using Eclipse, try to update the web module version in project.facet.core.xml. It should be in synch with the web.xml web-app version.