通过 Tomcat 配置将变量传递到 JRuby 应用程序

发布于 2024-10-05 08:57:53 字数 212 浏览 0 评论 0原文

在部署为 WAR 文件的 JRuby 应用程序中配置变量的最佳方法是什么?操作组需要根据我的应用程序的部署位置配置数据库设置和其他环境变量。由于它是 WAR 文件,因此它们无法直接访问 database.yml 或任何环境文件。

我希望能够改变他们需要配置的任何内容,并让他们将一些内容放入 Tomcat app.config/web.config 中。这可以吗?如何将这些值引入 JRuby?

What's the best way to configure variables in a JRuby application that's deployed as a WAR file? The operations group will need to configure database settings and other environment variables depending on where my app is deployed. Since it's a WAR file though they don't have direct access to the database.yml or any of the environment files.

I want to be able to variablize anything they need to configure and have them perhaps put something into the Tomcat app.config/web.config. Is this possible to do? How do you bring those values into JRuby?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最舍不得你 2024-10-12 08:57:53

因此,我发现,在 JRuby 中从 Tomcat servlet 上下文获取参数非常简单:

$servlet_context

例如,如果我在 web.xml 中定义了以下内容:

# from inside the web.xml context
<context-param>
  <param-value>jdbc:h2:localhost/~/test_db</param-value>
  <param-name>database.url</param-name>
</context-param>

您可以按如下方式访问 JRuby 中的值:

$servlet_context.getInitParameter("database.url")

这将返回字符串“jdbc: h2:localhost/~/test_db"。

So to get parameters from the Tomcat servlet context in JRuby is very simple I discovered:

$servlet_context

So for example if I had the following defined in the web.xml:

# from inside the web.xml context
<context-param>
  <param-value>jdbc:h2:localhost/~/test_db</param-value>
  <param-name>database.url</param-name>
</context-param>

You can access the value in JRuby as follows:

$servlet_context.getInitParameter("database.url")

This would return the string "jdbc:h2:localhost/~/test_db".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文