当尝试从 Eclipse 运行 jetty 时,我遇到了一个奇怪的情况。我将旧项目从jetty 7更新到jetty 9.3.7.v20160115。但是,现在当使用 m2eclipse 启动 jetty:run 时,出现以下异常:
java.lang.IllegalArgumentException: Object of class 'org.eclipse.jetty.maven.plugin.JettyWebAppContext' is not of type 'org.eclipse.jetty.webapp.WebAppContext'. Object Class and type Class are from different loaders. in file:/xx/WebApp/src/main/webapp/WEB-INF/jetty-env.xml
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:295)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:245)
at org.eclipse.jetty.plus.webapp.EnvConfiguration.configure(EnvConfiguration.java:116)
Run Code Online (Sandbox Code Playgroud)
从消息中我可以看到这两个类不一样。但从文档中我需要使用类 org.eclipse.jetty.webapp.WebAppContext 和 org.eclipse.jetty.maven.plugin.JettyWebAppContext 是 WebAppContext 的子类。所以我不清楚第 292 行中的条件是否
oClass.isInstance(obj)
Run Code Online (Sandbox Code Playgroud)
在那里正确使用。
我在 jetty-env.xml 文件中定义了以下条目:
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
<New id="resInspector" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg><Ref refid="wac"/></Arg>
<Arg>jdbc/xxx</Arg>
<Arg>
<New class="org.apache.commons.dbcp.BasicDataSource">
<Set name="driverClassName">org.postgresql.Driver</Set>
<Set name="url">jdbc:postgresql://xx:5432/xx</Set>
<Set name="username">xx</Set>
<Set name="password">xx</Set>
<Set name="maxActive">100</Set>
<Set name="maxIdle">30</Set>
<Set name="maxWait">-1</Set>
<Set name="defaultAutoCommit">false</Set> …Run Code Online (Sandbox Code Playgroud)