Jetty pool connection configuration error mysql: javax.naming.NameNotFoundException; remaining name is' env / jdbc / --- (mysql 5.0 + jetty 7.0.1)

My configuration files

Project / WEB-INF / web.xml:

<resource-ref>
    <description>ConnectionPool DataSource Reference</description>
    <res-ref-name>jdbc/mysql</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

Project / WEB-INF / Berth-env.xml:

<New id="mysql" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg></Arg>
<Arg>jdbc/mysql</Arg>
    <Arg>
        <New class="org.apache.commons.dbcp.BasicDataSource">
            <Set name="driverClassName">com.mysql.jdbc.Driver</Set>
            <Set name="url">jdbc:mysql://localhost:3306/db</Set>
            <Set name="username">user</Set>
            <Set name="password">pwd</Set>
            <Set name="maxActive">50</Set>
        </New>
    </Arg>
</New>

code to call:

ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:comp/env/jdbc/mysql");
con=ds.getConnection();

scripts to launch the berth:

java -DOPTIONS=plus -jar start.jar

java -jar start.jar

In any case, to start the berth, I received the following error:


javax.naming.NameNotFoundException; remaining name 'env/jdbc/mysql'
        at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:632)
        at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:663)
        at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:678)
        at org.eclipse.jetty.jndi.java.javaRootURLContext.lookup(javaRootURLContext.java:110)
        at javax.naming.InitialContext.lookup(Unknown Source)

Questions:

  • What is the problem?
  • Any other configurations needed?
  • where to put the following jar files:
    • Common-DBHP-1.2.2.jar
    • Mysql-socket-java-5.1.10-bin.jar

Thanks!

+5
source share
4 answers

Note. It is assumed that you are using Jetty 7.2.2+ (it may work with any Jetty 7.0 +).

, . , Jetty webapp, Jetty, jetty-env.xml webapp. , jetty.xml( ${JETTY_INSTALL_DIR}/etc:

<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>

Jetty , jetty-env.xml.

+10

. FYI, Jetty 6.1.22. - jetty-env.xml WEB-INF, . jetty-web.xml (.. Java: comp/env/jdbc/mydatasource) , .

+4

. /WEB -INF/jetty-env.xml :

<New id="DS" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg><Ref id="studentsApp"/></Arg>
    <Arg>jdbc/DS</Arg>
    <Arg>
        <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
            <Set name="Url">jdbc:mysql://localhost:3306/students</Set>
            <Set name="User">root</Set>
            <Set name="Password">root</Set>
        </New>
    </Arg>
</New>

. jndi scopes - . , java: comp/, jndi , . jndi:

Context t = (Context)new InitialContext().lookup("java:comp");
listContext(t, "");

private static final void listContext(Context ctx, String indent) {
    try {
        NamingEnumeration list = ctx.listBindings("");
        while (list.hasMore()) {
            Binding item = (Binding) list.next();
            String className = item.getClassName();
            String name = item.getName();
            System.out.println(indent + className + " " + name);
            Object o = item.getObject();
            if (o instanceof javax.naming.Context) {
                listContext((Context) o, indent + " ");
            }
        }
    } catch (NamingException ex) {
        System.out.println(ex);
    }
}

, jetty-web.xml - :

<Call class="org.eclipse.jetty.util.log.Log" name="info"><Arg>Starting my super test application</Arg></Call>

jetty-web.xml, .

jetty-web.xml context.xml, $JETTY_HOME/, MySQL $JETTY_HOME/lib/ext, .

, Jetty JNDI, jetty-web.xml.

0
source

The Jetty documentation points to a three-step process for using a JNDI resource, such as a database. These instructions should apply to Jetty 7 and Jetty 8.

  • Edit the file $JETTY_HOME/start.inias follows:
  • Change the server OPTIONSto include a plus, for example:

    OPTIONS=Server,jsp,jmx,resources,websocket,ext,plus

  • At the bottom of the file, in the "Configuration Files" section, add the following line after etc/jetty.xml:

    etc/jetty-plus.xml

-1
source

All Articles