Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6210709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:12:27+00:00 2026-05-24T06:12:27+00:00

I want to use connection pooling with Jetty 6 , but so far it

  • 0

I want to use connection pooling with Jetty 6, but so far it is giving my a lot of troubles.

I do

InitialContext context = new InitialContext();

It doesn’t throw an exception, but when I inspect the context variable I see this, which is kinda suspect:

enter image description here

Notice the defaultInitCtx=null.

The line after I try to get a datasource with:

Datasource dataSource = (DataSource)context.lookup("java:comp/env/MySQLDB");

and now I get an exception saying that there is no initial context:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

Obviously, I must be doing something wrong, but I just can’t find what…
If anyone could help, I would appreciate it!

Here is my jetty.xml:

<Configure id="Server" class="org.mortbay.jetty.Server">

... (all default except those lines I added)

  <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.webapp.JettyWebXmlConfiguration</Item>
          <Item>org.eclipse.jetty.webapp.TagLibConfiguration</Item>
      </Array>
  </Arg>
</Call>
</Configure>

My WEB-INF/web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-  app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Test</display-name>
  <servlet>
    <description></description>
    <display-name>Default</display-name>
    <servlet-name>Default</servlet-name>
    <servlet-class>Default</servlet-class>
 </servlet>
  <servlet-mapping>
    <servlet-name>Default</servlet-name>
    <url-pattern>/Default</url-pattern>
  </servlet-mapping>
  <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>MySQLDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
</web-app>

My WEB-INF/jetty-env.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"  "http://jetty.mortbay.org/configure.dtd">

<Configure class="org.mortbay.jetty.webapp.WebAppContext">  
<Set name="ConfigurationClasses">
   <Ref id="plusConfig"/>
</Set>


<!-- MySql datasource -->
<New id="MySQLDB" class="org.mortbay.jetty.plus.naming.Resource">
       <Arg></Arg>
       <Arg>MySQLDB</Arg>
       <Arg>
         <New class="org.apache.commons.dbcp.BasicDataSourceFactory">
           <Set name="driverClassName">com.mysql.jdbc.Driver</Set>
           <Set name="url">jdbc:mysql://host_ip</Set>
           <Set name="username">username</Set>
           <Set name="password">password</Set>
           <Set name="auth">Container</Set>
           <Set name="maxActive">-1</Set>
           <Set name="maxIdle">30</Set>
           <Set name="maxWait">10000</Set>
           <Set name="minEvictableIdleTimeMillis">600000</Set>
           <Set name="name">MySQLDB</Set>
           <Set name="removeAbandoned">true</Set>
           <Set name="removeAbandonedTimeout">5000</Set>
           <Set name="timeBetweenEvictionRunsMillis">10000</Set>
           <Set name="type">javax.sql.DataSource</Set>
        </New>
       </Arg>
     </New>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:12:29+00:00Added an answer on May 24, 2026 at 6:12 am

    You have to create jndi.properties file with values for factory to be used for initializing and put the file in the class path.

    If you are using jetty 7, the properties will be

    java.naming.factory.url.pkgs=org.eclipse.jetty.jndi
    java.naming.factory.initial=org.eclipse.jetty.jndi.InitialContextFactory
    

    PS: I have also come across with the problem and fixed it this way. I was using jetty 7 for my purpose. If you are using older versions, just identify the values for the same(if they are different).

    For jetty 6, I believe the properties should be (look at the API) (I haven’t tested this)

    java.naming.factory.url.pkgs=org.mortbay.naming
    java.naming.factory.initial=org.mortbay.naming.InitialContextFactory
    

    Later in your client code, you can check whether the factory is initialized properly

    try {
        InitialContext ic = new InitialContext();
        return (DataSource) ic.lookup("java:comp/env/MySQLDB");
    } catch (NamingException e) {
        logger.error("JNDI error while retrieving datasource" , e);
        throw new Exception(e);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use Connection pooling in my java web application with MySQL and
I want to use a capped collection in Mongo, but I don't want my
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want to use the connection string App.Config file. Also is it possible to
I am developing a java web Application and I use Tomcat connection pooling, here
I want to use connection pool with JPA/TopLink in my web app running on
I want use html5's new tag to play a wav file (currently only supported
I have this array that store the connection info and i want to use
I want to use a signals/slots library in a project that doesn't use QT.
When I try the following lookup in my code: Context initCtx = new InitialContext();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.