我似乎無法使用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