Taking your example, if the code expects to do a lookup of a datasource dependency using ctx.lookup("java:comp/env/jdbc/mydb")
then the corresponding resource-ref would look like :
You're not the only one that has found dealing with java:comp/env a bit confusing. That's one reason the Java EE 5 platform provides an alternative to context lookups() in the form of resource injection.
You might find the following presentation about component dependencies useful :
Regarding the portability of code using java:comp/env between Java EE implementations and stand-alone web servers like Tomcat, it's true that not all Java EE code can be used outside of Java EE. However, it's guaranteed to be portable to other Java EE implementations.