2012-04-26 7 views
3

jetty-mavenプラグインを使用してデータソースを追加できないようです。スローされたエラーはありませんが、コンテキストを見ると、データソースは追加されていません。私は、ファイルへのパスが正しいことと、そのクラスを解析していることを確認しています(不正なクラス名を入れるとエラーにつながります)。私はタグを使用してWebAppContext設定として設定しようとしましたが、このファイルは完全に無視されています。Jetty.xmlからJNDIデータソースを追加しないjetty-maven-plugin

の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"); 

任意の助けいただければ幸いです。

+0

私は同様の問題があり、桟橋ではないようですdefauktとjndiで設定されています。私は設定を探していますが、それは面倒です。 http://docs.codehaus.org/display/JETTY/JNDI –

答えて

0

それとも単にあなたのweb.xmlに追加します。

<resource-ref> 
    <res-ref-name>jdbc/postgres</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 
関連する問題