I'm using Jetty 9.2 (embedded) with the standard MySQL connector API and I'm very confused by how this is supposed to be setup. Currently, I have this in my web.xml file:
<webapp ...
<resource-ref>
<description>JDBC Data Source</description>
<res-ref-name>jdbc/DataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</webapp>
...and this in my jetty-env.xml:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<New id="DatabaseConnector" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/DataSource</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://localhost:3306/DBName</Set>
<Set name="User">user</Set>
<Set name="Password">pass</Set>
</New>
</Arg>
</New>
</Configure>
...and this code to initialize:
Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
DataSource datasource = (DataSource) envCtx.lookup("jdbc/DataSource");
When I try to fire up the server, I get the error javax.naming.NameNotFoundException; remaining name 'jdbc/DataSource'
. I've tried lots of different variations of the strings in the code initialization, like removing the lookup
call on the InitialContext
object, but I just keep getting variations of the same error with a different name
value;
Both of the xml files are located in my /WAR/WEB-INF
directory. I've looked at loads of previous questions and tutorials, blogs etc. but I'm getting nowhere.