[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jetty-users] Configuring Eclipse Jetty 8.1.5, MySQL 5.1 aka (where the <bleep> does a <resource-ref> go?)
|
Ken,
There are generally many different ways to acheive the same outcome in
jetty, so that's probably why you've seen different ways documented.
Generally having options is a good thing :)
In case there's any confusion, this is the definitive page:
http://wiki.eclipse.org/Jetty/Feature/JNDI
If there's something missing, then please let us know so we can update the page.
Your case is a little out-of-the-ordinary in that you are using
javaee-style features, but without a web.xml. This is not something
I've encountered before, but it sounds like something I should add to
the documentation.
I would recommend (as does the page above) that you put any jndi
definitions into a WEB-INF/jetty-env.xml file and *not* the context
xml file. If you do that, then you can effectively do what a web.xml
<resource-ref> element would do and bind your datasource into the
java:comp/env namespace by defining your resource and binding it into
java:comp/env in the one go (note this will *NOT* work in a context
xml file, it *must* be jetty-env.xml):
So do the following in WEB-INF/jetty-env.xml:
<New id="jdbc/myds" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/myds</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://localhost:3306/chat</Set>
<Set name="User">root</Set>
<Set name="Password">sillyness</Set>
</New>
</Arg>
<Call name="bindToENC">
<Arg>jdbc/myds</Arg>
</Call>
</New>
In the call to bindToENC bind whatever name you want to look up as the
suffix to java:comp/env. Eg if you want to lookup java:comp/env/my/foo
then the bindToENC argument would be "my/foo".
Jan
On 7 August 2012 06:29, Ken Corey <ken@xxxxxxxxxxxx> wrote:
> I'm struggling, so far in vain, to get database connection pooling working
> on Jetty.
>
> I've read *lots* of web pages, and they all have something different to say
> about how to configure this.
>
> I've ended up trying to configure a servlet via its gcm.xml file like so:
>
> |<?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
> "http://www.eclipse.org/jetty/configure.dtd">
> <Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
> <New id="jdbc/myds" class="org.eclipse.jetty.plus.jndi.Resource">
> <Arg></Arg>
> <Arg>jdbc/myds</Arg>
> <Arg>
> <New
> class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
> <Set name="Url">jdbc:mysql://localhost:3306/chat</Set>
> <Set name="User">root</Set>
> <Set name="Password">sillyness</Set>
> </New>
> </Arg>
> </New>
> <Set name="contextPath">/</Set>
> <Set name="war"><SystemProperty name="jetty.home"
> default="."/>/webapps/gcm</Set>
> <Set name="extractWAR">true</Set>
> </Configure>|
>
>
> My servlet gets called like this:
>
> | public static List<String> getDevices()
> throws javax.naming.NamingException, java.sql.SQLException {
> synchronized (regIds) {
> InitialContext ctx= new InitialContext();
> DataSource ds= (DataSource)ctx.lookup("java:comp/env/jdbc/myds");
> Connection conn= null;
> Statement stmt= null;
>
> try {
> conn= ds.getConnection();
>
> stmt= conn.createStatement();
> ResultSet rs= stmt.executeQuery("select * from chatdevice");
>
> //blah,blah,blah...
> |
>
>
> And all the documents I've seen suggest that I need to put a <resource-ref>
> section in my web.xml file...which of course doesn't exist.
>
> If I put the <resource-ref> in the gcm.xml file (anywhere), or if I put it
> into a web.xml file on its own, I'm told the file is not well formed.
>
> Can anyone tell me the magic combination to get it to work?
>
> Thanks,
>
> -Ken
> _______________________________________________
> jetty-users mailing list
> jetty-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/jetty-users
--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com – Developer advice, services and support
from the Jetty & CometD experts.