【发布时间】:2014-08-21 20:20:50
【问题描述】:
我正在以编程方式启动指向战争的 Jetty。我还在 WEB-INF 中有一个 jetty-env.xml,它定义了一个 JNDI 源。但是,在启动时,它给了我一个关于类加载器问题的错误。我认为是因为 main() 从 java 的 AppClassLoader 创建了一个 WebAppContext,而 JNDI 位于 jetty-env.xml 中定义的 WebAppContext 中。
java.lang.IllegalArgumentException: Object of class 'org.eclipse.jetty.webapp.WebAppContext' is not of type 'org.eclipse.jetty.webapp.WebAppContext'. Object Class and type Class are from different loaders. in file:/home/ckessel/Projects/exploded-war/WEB-INF/jetty-env.xml
我认为将嵌入式 Jetty 启动与 jetty-env.xml 结合起来并不奇怪,但我已经阅读了大量关于嵌入式 Jetty 和 JNDI 等的 eclipse Jetty 文档,但它没有似乎没有涵盖这种组合。
一个想法?
jetty-env.xml:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<New id="postgreSQL Datasource" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/postgres</Arg>
<Arg>
...postgres config stuff here...
</Arg>
</New>
</Configure>
main()...classlist 的东西是从http://www.eclipse.org/jetty/documentation/current/jndi-embedded.html 偷来的
public static void main(String[] args) throws Exception {
int port = 8080;
System.setProperty("org.eclipse.jetty.LEVEL", "DEBUG");
System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StdErrLog");
Server server = new Server(port);
// Enable parsing of jndi-related parts of web.xml and jetty-env.xml
Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(server);
classlist.addAfter(
"org.eclipse.jetty.webapp.FragmentConfiguration",
"org.eclipse.jetty.plus.webapp.EnvConfiguration",
"org.eclipse.jetty.plus.webapp.PlusConfiguration");
// Create the webapp for our war.
WebAppContext webapp = new WebAppContext();
webapp.setWar("/home/ckessel/Projects/build/exploded-war");
webapp.setContextPath("/");
server.setHandler(webapp);
server.start();
server.join();
}
【问题讨论】: