简体   繁体   English

使用IDEA IntelliJ Jetty插件(jetty-env.xml)配置数据源

[英]Configuring DataSources with IDEA IntelliJ Jetty Plugin (jetty-env.xml)

I'm trying to getting started with the IDEA IntelliJ Jetty Plugin. 我正在尝试IDEA IntelliJ Jetty插件的入门。 In our application we use a JNDI DataSource to access the actual database. 在我们的应用程序中,我们使用JNDI数据源访问实际的数据库。

For development therefore we generate a jetty-env.xml and include this in the WEB-INF directory during development deploys: 因此,对于开发而言,我们会生成一个jetty-env.xml并将其包含在开发部署期间的WEB-INF目录中:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
  <!-- Add an JNDI resource -->
  <New class="org.mortbay.jetty.plus.naming.Resource">
        <Arg>datasource_pbv</Arg>
        <Arg>
            <New class="org.apache.commons.dbcp.BasicDataSource">
                <Set name="DriverClassName">oracle.jdbc.driver.OracleDriver</Set>
                <Set name="Url">jdbc:oracle:thin:@dbserver:1521:DATABASE</Set>
                <Set name="Username">user</Set>
                <Set name="Password">pass</Set>
            </New>
        </Arg>
    </New>
</Configure>

I reconfigured the Jetty WebAppDeployer in jetty.xml that way, so it uses the org.mortbay.jetty.plus.webapp.EnvConfiguration which reads and processes the jetty-env.xml : 我以这种方式在jetty.xml中重新配置了Jetty WebAppDeployer ,因此它使用org.mortbay.jetty.plus.webapp.EnvConfiguration来读取和处理jetty-env.xml

<Configure id="Server" class="org.mortbay.jetty.Server">  
    ...
    <Array id="plusConfig" type="java.lang.String">
      <Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
      <Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
      <Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
      <Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
      <Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
    </Array>
    ...
    <Call name="addLifeCycle">
      <Arg>
        <New class="org.mortbay.jetty.deployer.WebAppDeployer">
            ...              
            <Set name="configurationClasses"><Ref id="plusConfig"/></Set>
        </New>
      </Arg>
    </Call>
    ...
</Configure>    

Unfortunately this doesn't work with the IDEA Jetty plugin. 不幸的是,这不适用于IDEA Jetty插件。 The IDEA Jetty Plugin generates a context-config.xml and a subsequent war-exploded.xml which does not add the EnvConfiguration. IDEA Jetty插件会生成一个context-config.xml和一个随后的war-exploded.xml ,其中不会添加EnvConfiguration。 Therefore the jetty-env.xml is ignored when deploying with the Jetty IDEA Plugin. 因此,在使用Jetty IDEA插件进行部署时,将忽略jetty-env.xml。

How can I make this work or are the other ways to provide custom JNDI entries when deploying using the IDEA Jetty Plugin? 在使用IDEA Jetty插件进行部署时,我该如何工作或提供自定义JNDI条目的其他方法?

I haven't checked myself, but since IDEA Jetty integration relies on ContextDeployer , the following should work (if added to jetty.xml ): 我没有检查自己,但因为IDEA码头一体化依赖于ContextDeployer ,下面应该工作(如果加入jetty.xml ):

<Call name="addLifeCycle">
  <Arg>
    <New class="org.mortbay.jetty.deployer.ContextDeployer">
        ...              
        <Set name="configurationClasses"><Ref id="plusConfig"/></Set>
    </New>
  </Arg>
</Call>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM