来自 IntelliJ 的码头运行不会读取 jetty-env.xml



我正在IntelliJ中调试,因为我似乎无法让JBoss运行(由于上下文和虚拟主机名问题),我使用Jetty 6.1.26。我能够在使用不涉及jndi的DB连接字符串时运行和调试。

现在,我需要使用Jndi,但似乎无法让Jetty找到它。我在WEB-INF目录中创建了一个jetty-env.xml文件,如下所示:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="wac" class="org.mortbay.jetty.webapp.WebAppContext">
    <New id="jdbc.datasource" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg><Ref id="wac"/></Arg>
        <Arg>jdbc/datasourceArg>
        <Arg>
            <New class="oracle.jdbc.pool.OracleDataSource">
                <Set name="URL">jdbc:oracle:thin:@localhost:1521:xe</Set>
                <Set name="User">user</Set>
                <Set name="Password">password</Set>
            </New>
        </Arg>
    </New>
</Configure>

网络。

<resource-ref>
    <description>ConnectionPool DataSource Reference</description>
    <res-ref-name>jdbc.datasource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
这样

,然后应用程序上下文用它创建一个bean:

<jee:jndi-lookup id="jndiDataSource" jndi-name="jdbc.datasource"/>

当我运行jetty时,它告诉我它找不到数据源,因此它无法创建bean,并且应用程序无法启动。

我怀疑问题是jetty实际上没有读取xml文件。我在里面放了垃圾,只是想看看,在启动时肯定没有错误。

我添加了+到我的jetty xml

<Call name="addLifeCycle">
  <Arg>
    <New class="org.mortbay.jetty.deployer.WebAppDeployer">
      <Set name="contexts"><Ref id="Contexts"/></Set>
      <Set name="webAppDir"><SystemProperty name="jetty.home" default="."/>/webapps</Set>
      <Set name="parentLoaderPriority">false</Set>
      <Set name="extract">true</Set>
      <Set name="allowDuplicates">false</Set>
      <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
      <Set name="configurationClasses"><Ref id="plusConfig"/></Set>
    </New>
</Arg>
</Call>

,我引用了IntelliJ中jetty服务器设置中的plus xml。

我已经无计可施了。所有在线内容都告诉我,jetty会自动扫描该目录以查找此文件,但显然对我来说并没有发生。

您的问题看起来不像是由Intellij IDEA引起的。我建议您尝试运行Jetty与您的工件和启动无IDEA配置,比较结果。如果有差异,请提交bug报告。

我不熟悉数据源配置,但能够指出一些配置可能存在的问题:

  1. 在xpath /Configure/New/@class下的文件jetty-env.xml中应该是"org.mortbay.jetty.plus.naming.Resource"而不是"org.eclipse.jetty.plus.jndi.Resource",因为根包Jetty 6.1.26版本为"org.mortbay.jetty"后来的版本把它改成了"org.eclipse.jetty"服务器。请注意,包的最后一部分也不同("naming",而不是"jndi")

  2. 在xpath /Configure/New/@id下的文件jetty-env.xml中应该是"datasource"代替"jdbc.datasource" (id无前缀)

  3. 文件jetty-env.xml第一个<Arg>(包含<Ref id="wac"/>)

  4. 在文件jetty-env.xml第二个<Arg>没有正确关闭(看起来

  5. 文件web.xml(不是web.inf) <res-ref-name>应该包含"jdbc/datasource"代替"jdbc.datasource",和在<jee:jndi-lookup>中一样,jndi-name属性应该是"jdbc/datasource"代替"jdbc.datasource",因为"jdbc/"(而不是"jdbc.")是中数据源名称的通用前缀Jetty .

  6. 我建议将数据源id更改为稍微多一些而不仅仅是"datasource",至少是"myDatasource"

235取自以下文章:

  • http://jkollage.blogspot.com/2008/01/jndi-with-jetty-env.html
  • http://www.plugtree.com/jetty-datasource-jta/

五年多以后,我遇到了同样的问题:jetty run-war运行配置没有拾取我在构建资源中定义的jety -env.xml。

修复结果是更新运行配置的命令行,以包括compile生命周期阶段,完整的clean compile jetty:run-war -f pom.xml

最新更新