Jetty 7:为Start.java配置JNDI

继Wicket 1.5领先后,我将一个项目从Jetty 6.1.25转换为7.5.0.v20110901。 我现有的Start.java包含以下设置,我用它来配置JNDI:

  EnvConfiguration envConfiguration = new EnvConfiguration(); URL url = new File("src/main/webapp/WEB-INF/jetty-env.xml").toURI().toURL(); envConfiguration.setJettyEnvXml(url); bb.setConfigurations(new Configuration[]{new WebInfConfiguration(), envConfiguration, new org.mortbay.jetty.plus.webapp.Configuration(), new JettyWebXmlConfiguration(), new TagLibConfiguration()}); 

然后我的jetty-env.xml有以下内容:

   jdbc/myapp   com.mysql.jdbc.Driver jdbc:mysql://localhost/myapp?characterEncoding=utf8 username password     

这在Jetty 6中运行得很好,但在7中, org.mortbay.jetty.plus.webapp.Configuration似乎不存在(或者我可能错过了一个Jar)。

有人可以给我一些关于如何使用Jetty 7配置JNDI的指导吗?

将以下内容放入src / test / jetty / jetty-env.xml:

   jdbc/mydatasource   jdbc:mysql://localhost/mydatabase?characterEncoding=utf8 username password     

然后修改Start.java以定义以下属性:

 System.setProperty("java.naming.factory.url.pkgs", "org.eclipse.jetty.jndi"); System.setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory"); 

并将以下配置添加到WebAppContext:

 EnvConfiguration envConfiguration = new EnvConfiguration(); URL url = new File("src/test/jetty/jetty-env.xml").toURI().toURL(); envConfiguration.setJettyEnvXml(url); bb.setConfigurations(new Configuration[]{ new WebInfConfiguration(), envConfiguration, new WebXmlConfiguration() }); 

我博客上的详细信息。

从Jetty 7开始,包名称已从org.mortbay.jetty更改为org.eclipse.jetty

此外, org.eclipse.jetty.plus.webapp.Configuration在7.2.0版中重命名,新名称为PlusConfiguration 。 我猜这是为了避免与org.eclipse.jetty.webapp.Configuration的名字冲突。