I ran into a problem today: When using the command mvn tomcat:run (the maven tomcat plugin) to quickly run a Tomcat instance and edit some JSPs on the fly I noticed my application was unable to find it’s JNDI defined DataSource:
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
But this DataSource is defined in the src/main/webapp/META-INF/context.xml default context file:
<Context>
<Resource name="jdbc/dbname" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="username" password="pass" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/dbname?autoReconnect=true"/>
</Context>
So I searched the web for other people with these kind of issues and found a few mailinglist questions (all unanswered) here and here. And finally found out that it is just not possible to use a context.xml with the tomcat:run goal as it is still an open issue in the codehaus JIRA: #MOJO-594. So I hope this might save someone some time searching for how to get tomcat to pickup the context.





Thank you. Unfortunatly, I found your website _after_ trying to get the jndi running for 2 hours now.
It took me a lot of time as well, which was the reason for this post
. We’ve switched most of our local testing to the Maven Jetty plugin. It supports JNDI in the jetty-env.xml config-file, or any other file you setup from pom.xml.