Jetty mysql连接池配置错误:javax.naming.NameNotFoundException;剩余名称';env/jdbc/--(mysql 5.0+;jetty 7.0.1)

Jetty mysql连接池配置错误:javax.naming.NameNotFoundException;剩余名称';env/jdbc/--(mysql 5.0+;jetty 7.0.1),java,mysql,jdbc,jetty,connection-pooling,Java,Mysql,Jdbc,Jetty,Connection Pooling,我的配置文件 project/WEB-INF/WEB.xml: 启动jetty的脚本: java -DOPTIONS=plus -jar start.jar java -jar start.jar 无论采用哪种方式启动jetty,我都会遇到以下错误: 问题是: 这里有什么问题 需要其他配置吗 在何处放置以下jar文件: commons-dbcp-1.2.2.jar mysql-connector-java-5.1.10-bin.jar 谢谢大家! 面临同样的问题。 我的项目/W

我的配置文件

project/WEB-INF/WEB.xml:


启动jetty的脚本:

java -DOPTIONS=plus -jar start.jar

java -jar start.jar
无论采用哪种方式启动jetty,我都会遇到以下错误:



问题是:

  • 这里有什么问题
  • 需要其他配置吗
  • 在何处放置以下jar文件:
    • commons-dbcp-1.2.2.jar
    • mysql-connector-java-5.1.10-bin.jar

谢谢大家!

面临同样的问题。 我的项目/WEB-INF/jetty-env.xml是:

我确信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/contexts中,将MySQL连接器jar放入$jetty_HOME/lib/ext中并开始工作

如果JNDI条目是从Jetty web.xml加载的,那么Jetty可能会遇到问题

注意:以下假设您使用的是Jetty 7.2.2+(可能适用于任何Jetty 7.0+)。 问题是你缺少了一个额外的间接层。即使您已经在webapp中配置了Jetty,您仍然需要告诉Jetty容器它需要在webapp中查找Jetty-env.xml。为此,请将以下内容添加到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>

org.eclipse.jetty.webapp.configuration
org.eclipse.jetty.webapp.webinf配置
org.eclipse.jetty.webapp.WebXmlConfiguration
org.eclipse.jetty.webapp.MetaInfConfiguration
org.eclipse.jetty.webapp.FragmentConfiguration
org.eclipse.jetty.plus.webapp.EnvConfiguration
org.eclipse.jetty.plus.webapp.plus配置
org.eclipse.jetty.webapp.JettyWebXmlConfiguration
org.eclipse.jetty.webapp.TagLibConfiguration

现在Jetty将知道如何解析您创建的Jetty-env.xml。

这让我整天发疯。仅供参考,我正在使用Jetty 6.1.22。对第一篇文章的评论已步入正轨——我在WEB-INF中有一个文件名Jetty-env.xml,它被忽略了。我将其重命名为Jetty-WEB.xml,并指定了数据源的全名(即java:comp/env/jdbc/mydatasource)用于新指令的第二个参数,它起作用。

用于使用JNDI资源,如数据库。这些指令应适用于Jetty 7和Jetty 8

  • 编辑
    $JETTY_HOME/start.ini
    文件,如下所示:
  • 修改服务器
    选项
    以包含“plus”,例如:

    OPTIONS=Server、jsp、jmx、resources、websocket、ext和plus

  • 在文件底部的“配置文件”部分,在
    etc/jetty.xml
    之后添加以下行:

    etc/jetty plus.xml


  • “剩余名称‘env”似乎表明找不到整个环境。jetty-env.xml是否已加载?也许您需要将其添加到-DOPTIONS或其他内容中?帮助了我,这正是我所缺少的。Jetty8也是顺便说一句。谢谢!我非常感谢您回答了一个一年前的问题,因为这对我帮助很大,谢谢!我是也使用Jetty 8。我想你没有开玩笑。我也非常渴望得到这个答案。这也是我必须要做的。我使用Jetty Hightite 7.0.1此修复程序对我有效,感谢你回答一篇较旧的帖子。我必须在我的声明中添加完整的路径名,如:java:comp/env/jdbc/DBName org.postgres驱动程序jdbc:postgresql://localhost:5432/db …我不能像这样使用contexts文件夹,或者我会这样使用。有关解决方案,请参见上文Sean的评论。我也有同样的问题,我遵循了文档,最后我不得不在声明中使用完整的jndi路径,例如“java:comp/env/jdbc/DBName”我在jetty.xml中添加了我的,以在开始时保持简单。
    java -DOPTIONS=plus -jar start.jar
    
    java -jar start.jar
    
    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)
    
    <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>
    
    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);
        }
    }
    
    <Call class="org.eclipse.jetty.util.log.Log" name="info"><Arg>Starting my super test application</Arg></Call>
    
    <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>