参数化 EAR

发布于 2024-09-10 11:06:56 字数 593 浏览 3 评论 0原文

我想为部署在 Glassfish 服务器上的 Java EE 应用程序设置一些只读参数(例如 RMI 注册表主机和端口)。通常执行此操作的位置是部署描述符,但我的问题是它打包在 EAR 中,因此我无法在不更改 EAR 的情况下编辑它。

我需要类似于设置 JDBC 和 JMS 资源的东西,但要简单得多。我可以将配置数据放入数据库表中,但这似乎有点过分了。我可以使用文件资源适配器,但最好可以在 Glassfish 管理控制台中编辑配置。

有没有标准的方法来做到这一点?当应用程序依赖于需要与之通信的外部节点时,如何测试应用程序?我应该把这些参数放在哪里以及如何访问它们?

我最好的猜测是定义外部 JNDI 资源,但是我该将数据放在哪里呢?

更新:这就是我的想法:

如何在 EAR 或 WAR 之外存储 Java EE 配置参数?

所以问题是:如何在 Glassfish 中执行此操作?

I would like to set some read-only parameters (eg. an RMI registry host and port) to a Java EE application deployed on a Glassfish server. The usual place to do this would be the deployment descriptor, but my problem is that it is packaged in the EAR, so I cannot edit it without changing the EAR.

I need something similar to setting JDBC and JMS resources, but much simpler. I could put the configuration data in a database table but that seems to be overkill. I could use the File Resource Adapter, but it would be best if I could edit the configuration in the Glassfish Admin Console.

Is there a standard way to do this? How do you test your applications when they depend on external nodes they need to be communicating with? Where shall I put these parameters and how can I access them?

My best guess was to define external JNDI resources, but then where do I put the data?

UPDATE: this is what I was thinking of:

How can I store Java EE configuration parameters outside of an EAR or WAR?

So the question is: how do I do this in Glassfish?

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

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

发布评论

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

评论(1

很酷又爱笑 2024-09-17 11:06:56

经过几个小时的谷歌搜索,我找到了答案!这并不简单,但幸运的是非常容易。这是:

http://www.mentby.com/glassfish/custom-resource-work-when-looking-it-up-but-not-with-injection.html

创建自定义资源名为“value”的属性。像这样:

替代文本 http://img231.imageshack.us/img231/8237/jndicustomresource .png

然后从 EJB 访问这个名称/值非常容易

try {
     InitialContext ic = new InitialContext();
     String value = (String) ic.lookup("MyCustomResource");
     System.out.println("MyCustomResource = " + value);
} catch (NamingException e) {
     e.printStackTrace();
}

信息:MyCustomResource = 来自 MyCustomResource 的一个大大的拥抱!

After a few hours of googling I found the answer! It's not trivial, but luckily very easy. Here it is:

http://www.mentby.com/glassfish/custom-resource-work-when-looking-it-up-but-not-with-injection.html

Create a Custom Resource on the Admin Console, and add a Property called "value". Like this:

alt text http://img231.imageshack.us/img231/8237/jndicustomresource.png

Then accessing this name/value is really easy from the EJB:

try {
     InitialContext ic = new InitialContext();
     String value = (String) ic.lookup("MyCustomResource");
     System.out.println("MyCustomResource = " + value);
} catch (NamingException e) {
     e.printStackTrace();
}

Which prints

INFO: MyCustomResource = A big hug from MyCustomResource!

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