| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>Configuring JNDI</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, spdy, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty : The Definitive Reference"><link rel="up" href="jndi.html" title="Chapter 11. Configuring JNDI"><link rel="prev" href="using-jetty-jndi.html" title="Working with Jetty JNDI"><link rel="next" href="jndi-embedded.html" title="Using JNDI with Jetty Embedded"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><script type="text/javascript" src="js/shCore.js"></script><script type="text/javascript" src="js/shBrushJava.js"></script><script type="text/javascript" src="js/shBrushXml.js"></script><script type="text/javascript" src="js/shBrushBash.js"></script><script type="text/javascript" src="js/shBrushJScript.js"></script><script type="text/javascript" src="js/shBrushSql.js"></script><script type="text/javascript" src="js/shBrushProperties.js"></script><script type="text/javascript" src="js/shBrushPlain.js"></script><link type="text/css" rel="stylesheet" href="css/shCore.css"><link type="text/css" rel="stylesheet" href="css/shThemeEclipse.css"><link type="text/css" rel="stylesheet" href="css/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small"> |
| Version: 9.1.5.v20140505</span></td><td style="width: 50%"><script type="text/javascript"> (function() { |
| var cx = '016459005284625897022:obd4lsai2ds'; |
| var gcse = document.createElement('script'); |
| gcse.type = 'text/javascript'; |
| gcse.async = true; |
| gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + |
| '//www.google.com/cse/cse.js?cx=' + cx; |
| var s = document.getElementsByTagName('script')[0]; |
| s.parentNode.insertBefore(gcse, s); |
| })(); |
| </script><gcse:search></gcse:search></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Configuring JNDI</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="using-jetty-jndi.html"><i class="icon-chevron-left"></i> Previous</a> </td><th width="60%" align="center">Chapter 11. Configuring JNDI<br><a accesskey="p" href="index.html"><i class="icon-home"></i> Home</a></th><td width="20%" align="right"> <a accesskey="n" href="jndi-embedded.html">Next <i class="icon-chevron-right"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at |
| <span class="website">www.webtide.com</span></a></h5><p> |
| private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... |
| scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery |
| </p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="jndi-configuration"></a>Configuring JNDI</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="jndi-configuration.html#configuring-jndi-env-entries">Configuring JNDI <code class="code">env-entries</code></a></span></dt><dt><span class="section"><a href="jndi-configuration.html#configuring-resource-refs-and-resource-env-refs">Configuring <code class="code">resource-refs</code> and |
| <code class="code">resource-env-refs</code></a></span></dt><dt><span class="section"><a href="jndi-configuration.html#configuring-datasources">Configuring DataSources</a></span></dt><dt><span class="section"><a href="jndi-configuration.html#configuring-jms-queues-topics-connectionfactories">Configuring JMS Queues, Topics and ConnectionFactories</a></span></dt><dt><span class="section"><a href="jndi-configuration.html#configuring-mail-with-jndi">Configuring Mail</a></span></dt><dt><span class="section"><a href="jndi-configuration.html#configuring-xa-transactions">Configuring XA Transactions</a></span></dt><dt><span class="section"><a href="jndi-configuration.html#configuring-links">Configuring Links</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="configuring-jndi-env-entries"></a>Configuring JNDI <code class="code">env-entries</code></h3></div></div></div><p>Sometimes it is useful to pass configuration information to a webapp |
| at runtime that you either cannot or cannot conveniently code into a |
| <code class="code">web.xml env-entry</code>. In such cases, you can use <code class="code"> |
| org.eclipse.jetty.plus.jndi.EnvEntry</code>, and even override an entry of |
| the same name in <code class="filename"> web.xml</code>.</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[<New class="org.eclipse.jetty.plus.jndi.EnvEntry"> |
| <Arg></Arg> |
| <Arg>mySpecialValue</Arg> |
| <Arg type="java.lang.Integer">4000</Arg> |
| <Arg type="boolean">true</Arg> |
| </New> ]]> |
| </script></div><p>This example defines a virtual <code class="code">env-entry</code> called |
| <code class="code">mySpecialValue</code> with value <code class="code">4000</code> that is <a class="link" href="using-jetty-jndi.html#jndi-name-scope" title="Scope of Resource Names">scoped</a> to the JVM. It is put into JNDI at |
| <code class="code"> java:comp/env/mySpecialValue</code> for <span class="emphasis"><em>every</em></span> |
| web app deployed. Moreover, the boolean argument indicates that this value |
| overrides an <code class="code">env-entry</code> of the same name in |
| <code class="code">web.xml</code>. If you don't want to override, omit this |
| argument, or set it to <code class="code">false</code>.</p><p>The Servlet Specification allows binding only the following object |
| types to an <code class="code">env-entry</code>:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p> java.lang.String </p></li><li class="listitem"><p> java.lang.Integer </p></li><li class="listitem"><p> java.lang.Float </p></li><li class="listitem"><p> java.lang.Double </p></li><li class="listitem"><p> java.lang.Long </p></li><li class="listitem"><p> java.lang.Short </p></li><li class="listitem"><p> java.lang.Character </p></li><li class="listitem"><p> java.lang.Byte </p></li><li class="listitem"><p> java.lang.Boolean </p></li></ul></div><p>That being said, Jetty is a little more flexible and allows you to |
| also bind custom POJOs, <a class="link" href="http://docs.oracle.com/javase/1.5.0/docs/api/javax/naming/Reference.html" target="_top"> |
| <code class="code">javax.naming.References</code></a> and <a class="link" href="http://docs.oracle.com/javase/1.5.0/docs/api/javax/naming/Referenceable.html" target="_top"> |
| <code class="code">javax.naming.Referenceables</code></a>. Be aware that if you take |
| advantage of this feature, your web application is <span class="emphasis"><em>not |
| portable</em></span>.</p><p>To use the <code class="code">env-entry</code> configured above, use code in your |
| <code class="filename">servlet/filter/etc.</code>, such as:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: java;toolbar: false"> |
| <![CDATA[import javax.naming.InitialContext; |
| |
| public class MyClass { |
| |
| public void myMethod() { |
| |
| InitialContext ic = new InitialContext(); |
| Integer mySpecialValue = (Integer)ic.lookup("java:comp/env/mySpecialValue"); |
| ... |
| } |
| } ]]> |
| </script></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="configuring-resource-refs-and-resource-env-refs"></a>Configuring <code class="code">resource-refs</code> and |
| <code class="code">resource-env-refs</code></h3></div></div></div><p>You can configure any type of resource that you want to refer to in |
| a <code class="code">web.xml</code> file as a <code class="code">resource-ref</code> or |
| <code class="code">resource-env-ref</code>, using the <code class="code"> |
| org.eclipse.jetty.plus.jndi.Resource</code> type of naming entry. You |
| provide the scope, the name of the object (relative to |
| <code class="code">java:comp/env</code>) and a POJO instance or a |
| <code class="code">javax.naming.Reference</code> instance or |
| <code class="code">javax.naming.Referenceable</code> instance.</p><p>The <a class="link" href="http://jcp.org/aboutJava/communityprocess/pr/jsr244/index.html" target="_top">J2EE |
| Specification</a> recommends storing DataSources in |
| <code class="code">java:comp/env/jdbc</code>, JMS connection factories under |
| <code class="code">java:comp/env/jms</code>, JavaMail connection factories under <code class="code"> |
| java:comp/env/mail</code> and URL connection factories under |
| <code class="code">java:comp/env/url</code>. For example:</p><div class="table"><a name="d0e9773"></a><p class="title"><b>Table 11.1. DataSource Declaration Conventions</b></p><div class="table-contents"><table summary="DataSource Declaration Conventions" width="100%" border="1"><colgroup><col><col><col></colgroup><thead><tr><th align="center">Resource Type</th><th align="center">Name in <code class="code">jetty.xml</code></th><th align="center">Environment Lookup</th></tr></thead><tbody><tr><td>javax.sql.DataSource</td><td>jdbc/myDB</td><td>java:comp/env/jdbc/myDB</td></tr><tr><td>javax.jms.QueueConnectionFactory</td><td>jms/myQueue</td><td>java:comp/env/jms/myQueue</td></tr><tr><td>javax.mail.Session</td><td>mail/myMailService</td><td>java:comp/env/mail/myMailService</td></tr></tbody></table></div></div><br class="table-break"></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="configuring-datasources"></a>Configuring DataSources</h3></div></div></div><p>Here is an example of configuring a |
| <code class="code">javax.sql.DataSource</code>. Jetty can use any DataSource |
| implementation available on its classpath. In this example, the DataSource |
| is from the <a class="link" href="http://db.apache.org/derby" target="_top">Derby</a> |
| relational database, but you can use any implementation of a |
| <code class="code">javax.sql.DataSource</code>. This example configures it as scoped to |
| a web app with the id of <span class="emphasis"><em> wac</em></span>:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext"> |
| <New id="myds" class="org.eclipse.jetty.plus.jndi.Resource"> |
| <Arg><Ref refid="wac"/></Arg> |
| <Arg>jdbc/myds</Arg> |
| <Arg> |
| <New class="org.apache.derby.jdbc.EmbeddedDataSource"> |
| <Set name="DatabaseName">test</Set> |
| <Set name="createDatabase">create</Set> |
| </New> |
| </Arg> |
| </New> |
| </Configure>]]> |
| </script></div><p>The code above creates an instance of |
| <code class="code">org.apache.derby.jdbc.EmbeddedDataSource</code>, calls the two |
| setter methods <code class="code">setDatabaseName("test"),</code> and |
| <code class="code">setCreateDatabase("create"),</code> and binds it into the JNDI scope |
| for the web app. If you do not have the appropriate |
| <code class="code">resource-ref</code> set up in your <code class="code">web.xml</code>, it is |
| available from application lookups as <code class="code"> |
| java:comp/env/jdbc/myds</code>.</p><p>Here's an example <code class="filename">web.xml</code> declaration for the |
| datasource above:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[<resource-ref> |
| <res-ref-name>jdbc/myds</res-ref-name> |
| <res-type>javax.sql.DataSource</res-type> |
| <res-auth>Container</res-auth> |
| </resource-ref> ]]> |
| </script></div><p>To look up your DataSource in your <code class="filename">servlet/filter/etc.</code>:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: java;toolbar: false"> |
| <![CDATA[import javax.naming.InitialContext; |
| import javax.sql.DataSource; |
| |
| public class MyClass { |
| |
| public void myMethod() { |
| |
| InitialContext ic = new InitialContext(); |
| DataSource myDS = (DataSource)ic.lookup("java:comp/env/jdbc/myds"); |
| |
| ... |
| } |
| }]]> |
| </script></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><i class="icon-asterisk"></i> Note</h3><p>Careful! When configuring Resources, ensure that the type of |
| object you configure matches the type of object you expect to look up in |
| <code class="code">java:comp/env</code>. For database connection factories, this |
| means that the object you register as a Resource |
| <span class="emphasis"><em>must</em></span> implement the |
| <code class="code">javax.sql.DataSource</code> interface.</p></div><p>For more examples of datasource configurations, see <a class="xref" href="jndi-datasource-examples.html" title="Datasource Examples">Datasource Examples</a>.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="configuring-jms-queues-topics-connectionfactories"></a>Configuring JMS Queues, Topics and ConnectionFactories</h3></div></div></div><p>Jetty can bind any implementation of the JMS destinations and |
| connection factories. You just need to ensure the implementation Jars are |
| available on Jetty's classpath. Here is an example of binding an <a class="link" href="http://activemq.apache.org" target="_top">ActiveMQ</a> in-JVM connection |
| factory:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext"> |
| <New id="cf" class="org.eclipse.jetty.plus.jndi.Resource"> |
| <Arg><Ref refid='wac'/></Arg> |
| <Arg>jms/connectionFactory</Arg> |
| <Arg> |
| <New class="org.apache.activemq.ActiveMQConnectionFactory"> |
| <Arg>vm://localhost?broker.persistent=false</Arg> |
| </New> |
| </Arg> |
| </New> |
| </Configure>]]> |
| </script></div><p>The entry in <code class="filename">web.xml</code> would be:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[<resource-ref> |
| <res-ref-name>jms/connectionFactory</res-ref-name> |
| <res-type>javax.jms.ConnectionFactory</res-type> |
| <res-auth>Container</res-auth> |
| </resource-ref>]]> |
| </script></div><p>TODO: put in an example of a QUEUE from progress demo</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="configuring-mail-with-jndi"></a>Configuring Mail</h3></div></div></div><p>Jetty also provides infrastructure for access to |
| <code class="code">javax.mail.Sessions</code> from within an application:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext"> |
| <New id="mail" class="org.eclipse.jetty.plus.jndi.Resource"> |
| <Arg><Ref refid="wac"/></Arg> |
| <Arg>mail/Session</Arg> |
| <Arg> |
| <New class="org.eclipse.jetty.jndi.factories.MailSessionReference"> |
| <Set name="user">fred</Set> |
| <Set name="password">OBF:1xmk1w261z0f1w1c1xmq</Set> |
| <Set name="properties"> |
| <New class="java.util.Properties"> |
| <Put name="mail.smtp.host">XXX</Put> |
| <Put name="mail.from">me@me</Put> |
| <Put name="mail.debug">true</Put> |
| </New> |
| </Set> |
| </New> |
| </Arg> |
| </New> |
| </Configure> ]]> |
| </script></div><p>This setup creates an instance of the <code class="code"> |
| org.eclipse.jetty.jndi.factories.MailSessionReference</code> class, calls |
| its setter methods to set up the authentication for the mail system, and |
| populates a set of Properties, setting them on the <code class="code"> |
| MailSessionReference</code> instance. The result is that an application |
| can look up <code class="code"> java:comp/env/mail/Session</code> at runtime and obtain |
| access to a <code class="code">javax.mail.Session</code> that has the necessary |
| configuration to permit it to send email via SMTP.</p><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><i class="icon-lightbulb"></i> Tip</h3><p>You can set the password to be plain text, or use Jetty's <a class="link" href="configuring-security-secure-passwords.html" title="Secure Password Obfuscation">Secure Password |
| Obfuscation</a> (OBF:) mechanism to make the config file a little |
| more secure from prying eyes. Remember that you cannot use the other Jetty |
| encryption mechanisms of MD5 and Crypt because they do not allow you to recover the original |
| password, which the mail system requires.</p></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="configuring-xa-transactions"></a>Configuring XA Transactions</h3></div></div></div><p>If you want to perform distributed transactions with your resources, |
| you need a <span class="emphasis"><em>transaction manager</em></span> that supports the JTA |
| interfaces, and that you can look up as <code class="code">java:comp/UserTransaction</code> |
| in your webapp. Jetty does not ship with one as standard, but you can plug |
| in the one you prefer. You can configure a transaction manager using the |
| <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/plus/jndi/Transaction.html" target="_top">JNDI |
| Transaction</a> object in a Jetty config file. The following example |
| configures the <a class="link" href="http://www.atomikos.com/" target="_top">Atomikos</a> |
| transaction manager:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[<New id="tx" class="org.eclipse.jetty.plus.jndi.Transaction"> |
| <Arg> |
| <New class="com.atomikos.icatch.jta.J2eeUserTransaction"/> |
| </Arg> |
| </New>]]> |
| </script></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="configuring-links"></a>Configuring Links</h3></div></div></div><p>Generally, the name you set for your <code class="code">Resource</code> should be |
| the same name you use for it in <code class="filename">web.xml</code>. For example:</p><p>In a context xml file:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext"> |
| <New id="myds" class="org.eclipse.jetty.plus.jndi.Resource"> |
| <Arg><Ref refid="wac"/></Arg> |
| <Arg>jdbc/mydatasource</Arg> |
| <Arg> |
| <New class="org.apache.derby.jdbc.EmbeddedDataSource"> |
| <Set name="DatabaseName">test</Set> |
| <Set name="createDatabase">create</Set> |
| </New> |
| </Arg> |
| </New> |
| </Configure>]]> |
| </script></div><p>In <code class="filename">web.xml</code>:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[<resource-ref> |
| <res-ref-name>jdbc/mydatasource</res-ref-name> |
| <res-type>javax.sql.DataSource</res-type> |
| <res-auth>Container</res-auth> |
| <injection-target> |
| <injection-target-class>com.acme.JNDITest</injection-target-class> |
| <injection-target-name>myDatasource</injection-target-name> |
| </injection-target> |
| </resource-ref>]]> |
| </script></div><p>However, you can refer to it in <code class="filename">web.xml</code> by a different |
| name, and link it to the name in your <code class="code"> |
| org.eclipse.jetty.plus.jndi.Resource</code> by using an |
| <code class="code">org.eclipse.jetty.plus.jndi.Link</code>. For the example above, you |
| can refer to the <code class="code">jdbc/mydatasource</code> resource as <code class="code"> |
| jdbc/mydatasource1</code> as follows:</p><p>In a context xml file declare <code class="code">jdbc/mydatasource</code>:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext"> |
| <New id="myds" class="org.eclipse.jetty.plus.jndi.Resource"> |
| <Arg><Ref refid="wac"/></Arg> |
| <Arg>jdbc/mydatasource</Arg> |
| <Arg> |
| <New class="org.apache.derby.jdbc.EmbeddedDataSource"> |
| <Set name="DatabaseName">test</Set> |
| <Set name="createDatabase">create</Set> |
| </New> |
| </Arg> |
| </New> |
| </Configure>]]> |
| </script></div><p>Then in a <code class="filename">WEB-INF/jetty-env.xml</code> file, link the |
| name <code class="code">jdbc/mydatasource</code> to the name you want to reference it |
| as in <code class="filename">web.xml</code>, which in this case is |
| <code class="code">jdbc/mydatasource1</code>:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[<New id="map1" class="org.eclipse.jetty.plus.jndi.Link"> |
| <Arg><Ref refid='wac'/></Arg> |
| <Arg>jdbc/mydatasource1</Arg> <!-- name in web.xml --> |
| <Arg>jdbc/mydatasource</Arg> <!-- name in container environment --> |
| </New>]]> |
| </script></div><p>Now you can refer to <code class="code">jdbc/mydatasource1</code> in the |
| <code class="filename">web.xml</code> like this:</p><div class="informalexample"><script type="syntaxhighlighter" class="brush: xml;toolbar: false"> |
| <![CDATA[<resource-ref> |
| <res-ref-name>jdbc/mydatasource1</res-ref-name> |
| <res-type>javax.sql.DataSource</res-type> |
| <res-auth>Container</res-auth> |
| <injection-target> |
| <injection-target-class>com.acme.JNDITest</injection-target-class> |
| <injection-target-name>myDatasource</injection-target-name> |
| </injection-target> |
| </resource-ref>]]> |
| </script></div><p>This can be useful when you cannot change a JNDI resource directly in |
| the <code class="filename">web.xml</code> but need to link it to a specific |
| resource in your deployment environment.</p></div></div><script type="text/javascript"> |
| SyntaxHighlighter.all() |
| </script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="using-jetty-jndi.html"><i class="icon-chevron-left"></i> Previous</a> </td><td width="20%" align="center"><a accesskey="u" href="jndi.html"><i class="icon-chevron-up"></i> Top</a></td><td width="40%" align="right"> <a accesskey="n" href="jndi-embedded.html">Next <i class="icon-chevron-right"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Working with Jetty JNDI </td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="icon-home"></i> Home</a></td><td width="40%" align="right" valign="top"> Using JNDI with Jetty Embedded</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout"> |
| See an error or something missing? |
| <span class="callout"><a href="http://github.com/jetty-project/jetty-documentation">Contribute to this documentation at |
| <span class="website"><i class="icon-github"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2014-05-15T16:24:22-05:00)</i></span></div></p><script xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" type="text/javascript"> |
| var _gaq = _gaq || []; |
| _gaq.push(['_setAccount', 'UA-1149868-7']); |
| _gaq.push(['_trackPageview']); |
| |
| (function() { |
| var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; |
| ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
| var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); |
| })(); |
| </script></body></html> |