我似乎无法使用jetty-maven插件获取我的数据源。没有错误抛出,但是当我在上下文中没有添加数据源。我已经证实文件的路径是正确的,并且它正在解析它(放入不正确的类名导致错误)。我已经尝试使用标签并将其配置为WebAppContext配置,但该文件正在被完全忽略。jetty-maven-plugin不从Jetty.xml添加JNDI数据源资源
的pom.xml
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.3.v20120416</version>
<configuration>
<jettyXml>somePath/jetty.xml</jettyXml>
</configuration>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.0-801.jdbc4</version>
</dependency>
</dependencies>
</plugin>
的jetty.xml
<Configure class="org.eclipse.jetty.server.Server">
<New id="jdbc/postgres" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>jdbc/postgres</Arg>
<Arg>
<New class="org.postgresql.ds.PGSimpleDataSource">
<Set name="User">postgres</Set>
<Set name="Password">postgres</Set>
<Set name="DatabaseName">myDB</Set>
<Set name="ServerName">localhost</Set>
<Set name="PortNumber">5432</Set>
</New>
</Arg>
</New>
Java代码的
Context ctx = new InitialContext();
Context context = (Context) ctx.lookup("java:comp/env");
ds = (DataSource) context.lookup("jdbc/postgres");
任何帮助,将不胜感激。
我有类似的问题,似乎码头不通过与jndi defaukt进行配置。我在寻找配置,但它很棘手。 http://docs.codehaus.org/display/JETTY/JNDI – 2012-08-05 21:28:45