我正在尝试配置一个 JNDI 数据源,该数据源可以通过调用 Maven Jetty 插件来使用。我正在尝试在 WAR 文件外部执行此操作,以便以后可能使用 Jetty 部署我们的 Web 应用程序的任何人都不必在 WAR 的 WEB-INF 目录中编辑配置文件。我创建了一个 jetty.xml 文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<!-- Atomikos XA aware (but not XA capable) JDBC data source -->
<New id="sbeDataSource" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/myDataSource</Arg>
<Arg>
<New class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean">
.......
</New>
</Arg>
</New>
</Configure>
然后我从 Maven 插件中引用了这个文件,如下所示:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<jettyConfig>config/jetty.xml</jettyConfig>
</configuration>
</plugin>
但是,当我尝试通过 mvn jetty:run-war 运行 webapp 时,出现以下错误:
Embedded error:
Object is not of type class org.mortbay.jetty.webapp.WebAppContext
如果我省略了顶层 <Configure>
元素并尝试直接通过以下方式创建新的 JNDI 资源:
<New id="sbeDataSource" class="org.mortbay.jetty.plus.naming.Resource">
然后我得到一个类似的错误:
Embedded error:
Object is not of type class org.mortbay.jetty.plus.naming.Resource
什么给了?
最佳答案
根据documentation ,在 jetty.xml
中声明的命名条目应该是 jvm 或 Server 作用域:
As you can see, the most natural config files in which to declare naming entries of each scope are:
- jetty.xml - jvm or Server scope
- WEB-INF/jetty-env.xml or a context xml file - webapp scope
所以你的 jetty.xml
应该包含这样的东西:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="Server" class="org.mortbay.jetty.Server">
<!-- Atomikos XA aware (but not XA capable) JDBC data source -->
<New id="sbeDataSource" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/myDataSource</Arg>
<Arg>
<New class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean">
.......
</New>
</Arg>
</New>
</Configure>
关于java - Maven Jetty 插件中的 Jetty JNDI 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3925771/