This is how my jetty.xml looks after configuring datasource. Is this
correct? Since I'm still facing the same issue.

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "
http://www.eclipse.org/jetty/configure_9_0.dtd";>

<!-- =============================================================== -->
<!-- Documentation of this file format can be found at: -->
<!-- http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax -->
<!-- -->
<!-- Additional configuration files are available in $JETTY_HOME/etc -->
<!-- and can be mixed in. See start.ini file for the default -->
<!-- configuration files. -->
<!-- -->
<!-- For a description of the configuration mechanism, see the -->
<!-- output of: -->
<!-- java -jar start.jar -? -->
<!-- =============================================================== -->

<!-- =============================================================== -->
<!-- Configure a Jetty Server instance with an ID "Server" -->
<!-- Other configuration files may also configure the "Server" -->
<!-- ID, in which case they are adding configuration to the same -->
<!-- instance. If other configuration have a different ID, they -->
<!-- will create and configure another instance of Jetty. -->
<!-- Consult the javadoc of o.e.j.server.Server for all -->
<!-- configuration that may be set here. -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">

<!-- =========================================================== -->
<!-- Configure the Server Thread Pool. -->
<!-- The server holds a common thread pool which is used by -->
<!-- default as the executor used by all connectors and servlet -->
<!-- dispatches. -->
<!-- -->
<!-- Configuring a fixed thread pool is vital to controlling the -->
<!-- maximal memory footprint of the server and is a key tuning -->
<!-- parameter for tuning. In an application that rarely blocks -->
<!-- then maximal threads may be close to the number of 5*CPUs. -->
<!-- In an application that frequently blocks, then maximal -->
<!-- threads should be set as high as possible given the memory -->
<!-- available. -->
<!-- -->
<!-- Consult the javadoc of o.e.j.util.thread.QueuedThreadPool -->
<!-- for all configuration that may be set here. -->
<!-- =========================================================== -->
<Arg name="threadpool">
<New id="threadpool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<Arg name="minThreads" type="int">
<Property name="threads.min" default="10" />
</Arg>
<Arg name="maxThreads" type="int">
<Property name="threads.max" default="200" />
</Arg>
<Arg name="idleTimeout" type="int">
<Property name="threads.timeout" default="60000" />
</Arg>
<Set name="detailedDump">false</Set>
</New>
</Arg>

<!-- =========================================================== -->
<!-- Add shared Scheduler instance -->
<!-- =========================================================== -->
<Call name="addBean">
<Arg>
<New class="org.eclipse.jetty.util.thread.ScheduledExecutorScheduler" />
</Arg>
</Call>

<!-- =========================================================== -->
<!-- Http Configuration. -->
<!-- This is a common configuration instance used by all -->
<!-- connectors that can carry HTTP semantics (HTTP, HTTPS, SPDY) -->
<!-- It configures the non wire protocol aspects of the HTTP -->
<!-- semantic. -->
<!-- -->
<!-- This configuration is only defined here and is used by -->
<!-- reference from the jetty-http.xml, jetty-https.xml and -->
<!-- jetty-spdy.xml configuration files which instantiate the -->
<!-- connectors. -->
<!-- -->
<!-- Consult the javadoc of o.e.j.server.HttpConfiguration -->
<!-- for all configuration that may be set here. -->
<!-- =========================================================== -->
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Set name="secureScheme">https</Set>
<Set name="securePort">
<Property name="jetty.secure.port" default="8443" />
</Set>
<Set name="outputBufferSize">32768</Set>
<Set name="requestHeaderSize">8192</Set>
<Set name="responseHeaderSize">8192</Set>
<Set name="sendServerVersion">true</Set>
<Set name="sendDateHeader">false</Set>
<Set name="headerCacheSize">512</Set>

<!-- Uncomment to enable handling of X-Forwarded- style headers <Call
name="addCustomizer">
<Arg><New
class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
</Call> -->
</New>

<Call name="setAttribute">
<Arg>org.eclipse.jetty.webapp.configuration</Arg>
<Arg>
<Array type="java.lang.String">
<Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
<Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
<Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
<Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
<Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
<Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
<Item>org.eclipse.jetty.webapp.TagLibConfiguration</Item>
</Array>
</Arg>
</Call>

<!-- =========================================================== -->
<!-- Set the default handler structure for the Server -->
<!-- A handler collection is used to pass received requests to -->
<!-- both the ContextHandlerCollection, which selects the next -->
<!-- handler by context path and virtual host, and the -->
<!-- DefaultHandler, which handles any requests not handled by -->
<!-- the context handlers. -->
<!-- Other handlers may be added to the "Handlers" collection, -->
<!-- for example the jetty-requestlog.xml file adds the -->
<!-- RequestLogHandler after the default handler -->
<!-- =========================================================== -->
<Set name="handler">
<New id="Handlers"
class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New id="Contexts"
class="org.eclipse.jetty.server.handler.ContextHandlerCollection" />
</Item>
<Item>
<New id="DefaultHandler"
class="org.eclipse.jetty.server.handler.DefaultHandler" />
</Item>
</Array>
</Set>
</New>
</Set>

<!-- =========================================================== -->
<!-- extra server options -->
<!-- =========================================================== -->
<Set name="stopAtShutdown">true</Set>
<Set name="stopTimeout">5000</Set>
<Set name="dumpAfterStart">
<Property name="jetty.dump.start" default="false" />
</Set>
<Set name="dumpBeforeStop">
<Property name="jetty.dump.stop" default="false" />
</Set>
* <New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">*
* <Arg></Arg>*
* <Arg>jdbc/testDS</Arg>*
* <Arg>*
* <New class="com.mchange.v2.c3p0.ComboPooledDataSource">*
* <Set name="driverClass">org.h2.Driver</Set>*
* <Set name="jdbcUrl">jdbc:h2:/C:/data/test</Set>*
* <Set name="user">sa</Set>*
* <Set name="password"></Set>*
* </New>*
* </Arg>*
* </New>*
</Configure>



On Mon, Jul 29, 2013 at 3:10 PM, Jesse McConnell
<[email protected]>wrote:

> resource-ref in web.xml is typically the most portable way to wire a jndi
> resource into a webapp, jetty-env.xml typically lets you wire in jetty
> specific container configuration for declaring that jndi resource inside of
> the webapp....personally I prefer not seeing jetty-env.xml in a webapp and
> let the container configure it in a context.xml or globally in a jetty.xml
> formatted file.
>
> cheers,
> jesse
>
> --
> jesse mcconnell
> [email protected]
>
>
> On Mon, Jul 29, 2013 at 3:06 PM, Ranjith Koduri 
> <[email protected]>wrote:
>
>> Do I need to add a <resource-ref> to web.xml to get JNDI working or Is
>> it fine to configure jetty-env.xml as I did?
>>
>>
>> Thanks & Regards,
>> *Ranjith*
>> MS-MIS, Univ Of Illinois at Chicago.
>>
>>
>>
>>
>>
>> On Mon, Jul 29, 2013 at 2:27 PM, Ranjith Koduri <[email protected]
>> > wrote:
>>
>>> I moved webServer.start() before InitialContext but I'm getting the
>>> same error.
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Mon, Jul 29, 2013 at 2:16 PM, Joakim Erdfelt <[email protected]>wrote:
>>>
>>>> Your webServer.start() occurred after you attempted to lookup the JNDI
>>>> reference.
>>>> That's not going to work, as the deployment of the WebAppContext is the
>>>> one that sets up the JNDI reference.
>>>>
>>>> You essentially asked for the information before the information even
>>>> existed.
>>>>
>>>> Move the webServer.start() to before the InitialContext reference.
>>>>
>>>> --
>>>> Joakim Erdfelt <[email protected]>
>>>> webtide.com <http://www.webtide.com/>
>>>> Developer advice, services and support
>>>> from the Jetty & CometD experts
>>>> eclipse.org/jetty - cometd.org
>>>>
>>>>
>>>> On Mon, Jul 29, 2013 at 12:07 PM, Ranjith Koduri <
>>>> [email protected]> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>>   I need to implement JNDI for Jetty 9.0.3 web server for H2 database
>>>>> using C3p0 connection pooling, I've placed both H2 and C3p0 jars in 
>>>>> lib/ext
>>>>> of JETTY-HOME directory and I've created a jetty-env.xml file in my 
>>>>> WEB-INF.
>>>>>
>>>>> *WEB-INF/jetty-env.xml*
>>>>>
>>>>>  <?xml version="1.0"?>
>>>>>     <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD 
>>>>> Configure//EN" "http://jetty.mortbay.org/configure.dtd";>
>>>>>     <Configure class="org.eclipse.jetty.webapp.WebAppContext">
>>>>>         <New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
>>>>>             <Arg>jdbc/testDS</Arg>
>>>>>             <Arg>
>>>>>            <New class="com.mchange.v2.c3p0.ComboPooledDataSource">
>>>>>            <Set name="driverClass">org.h2.Driver</Set>
>>>>>            <Set name="jdbcUrl">jdbc:h2:/C:/data/test</Set>
>>>>>            <Set name="user">sa</Set>
>>>>>            <Set name="password"></Set>
>>>>>                 </New>
>>>>>             </Arg>
>>>>>         </New>
>>>>>     </Configure>
>>>>>
>>>>> I'm implementing embedded jetty with plus configuration enabled, by
>>>>> creating an instance of Jetty server from the main method of below class :
>>>>> *WebServer.java*
>>>>>
>>>>> import java.io.File;
>>>>> import javax.naming.Context;
>>>>> import javax.naming.InitialContext;
>>>>> import javax.sql.DataSource;
>>>>> import org.eclipse.jetty.server.Server;
>>>>> import org.eclipse.jetty.util.resource.ResourceCollection;
>>>>> import org.eclipse.jetty.webapp.WebAppContext;
>>>>>
>>>>> public class WebServer
>>>>> {
>>>>>
>>>>>     public static void main(String[] args)
>>>>>     {
>>>>>         // Creating Jetty Server on port 8080
>>>>>         Server webServer = new Server(8080);
>>>>>         org.eclipse.jetty.webapp.Configuration.ClassList classlist = 
>>>>> org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(webServer);
>>>>>         
>>>>> classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", 
>>>>> "org.eclipse.jetty.plus.webapp.EnvConfiguration",
>>>>>                 "org.eclipse.jetty.plus.webapp.PlusConfiguration");
>>>>>         WebAppContext wac = new WebAppContext();
>>>>>         // Set WAR Path to WebAppcontext from disk
>>>>>         File warPath = new File("C:/Users/XXXX/src/com/UI");
>>>>>         wac.setWar(warPath.getAbsolutePath());
>>>>>         wac.setContextPath("/");
>>>>>         wac.setBaseResource(new ResourceCollection(new String[] { 
>>>>> "./WebContent", "build/classes" }));
>>>>>         webServer.setHandler(wac);
>>>>>         try
>>>>>         {
>>>>>             InitialContext ic = new InitialContext();
>>>>>                 DataSource myDS = 
>>>>> (DataSource)ic.lookup("java:comp/env/jdbc/testDS");
>>>>>             System.out.println("param ::: "+myDS);
>>>>>             webServer.start();
>>>>>             webServer.join();
>>>>>         }
>>>>>         catch (Exception e)
>>>>>         {
>>>>>             e.printStackTrace();
>>>>>         }
>>>>>
>>>>>     }
>>>>>
>>>>> }
>>>>>
>>>>> I get following error, how can I resolve this?
>>>>>
>>>>> javax.naming.NameNotFoundException; remaining name 'env/jdbc/testDS'
>>>>>     at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:505)
>>>>>     at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:536)
>>>>>     at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:551)
>>>>>     at 
>>>>> org.eclipse.jetty.jndi.java.javaRootURLContext.lookup(javaRootURLContext.java:117)
>>>>>     at javax.naming.InitialContext.lookup(InitialContext.java:411)
>>>>>     at com.server.WebServer.main(WebServer.java:37)
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> jetty-users mailing list
>>>>> [email protected]
>>>>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> jetty-users mailing list
>>>> [email protected]
>>>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>>>
>>>>
>>>
>>
>> _______________________________________________
>> jetty-users mailing list
>> [email protected]
>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>
>>
>
> _______________________________________________
> jetty-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
>
_______________________________________________
jetty-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to