简体   繁体   English

对jetty-env.xml感到困惑

[英]Confused about jetty-env.xml

I have a webapp that uses JNDI to locate a datasource and a transaction manager. 我有一个使用JNDI来定位数据源和事务管理器的webapp。 I see from the Jetty documentation how to do this via the jetty-env.xml file. 我从Jetty文档中看到如何通过jetty-env.xml文件执行此操作。 However it mentions that this file should be put into the WEB-INF directory. 但是它提到应该将此文件放入WEB-INF目录中。

Why would they suggest that JNDI resources be configured in a configuration file that is located inside my WAR? 为什么他们建议在我的WAR内部的配置文件中配置JNDI资源? It makes no sense...I always thought of JNDI as a way to externalize configuration. 这没有任何意义......我一直认为JNDI是一种外部化配置的方式。 Is there another place I can put this file on a Jetty server machine? 还有另一个地方我可以把这个文件放在Jetty服务器上吗?

A follow up question: How about within my Maven WAR module...how should I deal with this file so that I can use the Maven jetty plugin for development, but not have the file end up in the WAR? 一个跟进问题:在我的Maven WAR模块中怎么样...我应该如何处理这个文件以便我可以使用Maven jetty插件进行开发,但是文件最终没有在WAR中?

Is there another place I can put this file on a Jetty server machine? 还有另一个地方我可以把这个文件放在Jetty服务器上吗?

The official JNDI page puts it like this: 官方JNDI页面如下:

There are 3 places in which you can define naming entries: 您可以在3个位置定义命名条目:

  1. jetty.xml 的jetty.xml
  2. WEB-INF/jetty-env.xml WEB-INF /码头-env.xml
  3. context xml file 上下文xml文件

Naming entries defined in a jetty.xml file will generally be scoped at either the jvm level or the Server level. jetty.xml文件中定义的命名条目通常在jvm级别或服务器级别作用域。 Naming entries in a jetty-env.xml file will generally be scoped to the webapp in which the file resides, although you are able to enter jvm or Server scopes if you wish, that is not really recommended. jetty-env.xml文件中的命名条目通常将限定为文件所在的webapp,但是如果您愿意,可以输入jvm或Server范围,这不是真正推荐的。 In most cases you will define all naming entries that you want visible to a particular Server instance, or to the jvm as a whole in a jetty.xml file. 在大多数情况下,您将定义您希望特定Server实例可见的所有命名条目,或者在jetty.xml文件中定义整个jvm。 Entries in a context xml file will generally be scoped at the level of the webapp to which it applies, although once again, you can supply a less strict scoping level of Server or jvm if you want. 上下文xml文件中的条目通常在其应用的webapp级别作用域,但是如果需要,可以再次提供不太严格的服务器或jvm的作用域级别。

Use jetty.xml to configure things "outside" the webapp. 使用jetty.xml配置webapp“之外”的内容。

A follow up question: How about within my Maven WAR module...how should I deal with this file so that I can use the Maven jetty plugin for development, but not have the file end up in the WAR? 一个跟进问题:在我的Maven WAR模块中怎么样...我应该如何处理这个文件以便我可以使用Maven jetty插件进行开发,但是文件最终没有在WAR中?

Use the jettyConfig parameter of the Maven Jetty Plugin : 使用Maven Jetty插件的jettyConfig参数:

jettyConfig Optional . jettyConfig 可选 The location of a jetty.xml file that will be applied in addition to any plugin configuration parameters. 除了任何插件配置参数之外还将应用的jetty.xml文件的位置。 You might use it if you have other webapps, handlers etc to be deployed, or you have other jetty objects that cannot be configured from the plugin. 如果您要部署其他Web应用程序,处理程序等,或者您有其他无法从插件配置的jetty对象,则可以使用它。

The jetty-env.xml is only an additional option to set JNDI parameters. jetty-env.xml只是设置JNDI参数的附加选项。 To set JNDI parameters outside of the WAR you can place them inside jetty.xml. 要在WAR之外设置JNDI参数,可以将它们放在jetty.xml中。

See a related post here and the Jetty docs for JNDI . 请参阅此处的相关帖子以及JNDIJetty文档

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

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