本文介绍了获取WebSphere app Server的实例名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Web服务将在Jboss App Server或Websphere app Server上运行。对于他们两个我需要知道实例名称,对于Jboss,我可以使用 System.getProperty(jboss.server.name),但是我可以将哪些用于WebSphere ?我不能使用特定于WebSphere的方法,我需要调用System.properties

My Web service will run on a Jboss App Server or a Websphere app Server. For both of them I need to know the instance name, for Jboss I can use System.getProperty("jboss.server.name"), but what can I use for WebSphere? I can't use WebSphere-specific methods, I need to call System.properties

谢谢

推荐答案

为了保持平台中立,您可以将变量设置为Websphere服务器的JVM参数(如果每个节点都是集群的,则为一个)。对于Websphere 7,您可以在管理控制台中找到以下内容...

To keep it platform neutral you can set a variable as a JVM argument for the Websphere server (one for each node if its clustered). For Websphere 7, you will find the following in the Admin Console ...

Servers > Server Types > Websphere application servers > [your cluster node] >
  >  Java and Process Management  > Process Definition > Java Virtual Machine >
    > Generic JVM arguments 

并添加如下变量...

and add a variable like this ...

-DServerName=serverNodeA

你可以然后访问代码中的值为...

You can then access the value in your code as ...

String serverName = System.getproperty("ServerName");

只要您有权向JVM添加参数,此技术就可以与所有应用程序服务器一起使用。我确信必须有Websphere特定的API来查询节点名称,但是你要在服务器上键入代码,这使得单元测试变得困难并且不可移植。我更喜欢这种方法。

This technique can be used with all application servers so long as you have access to add arguments to the JVM. I'm sure there must be Websphere specific API to query the node name, but then you're typing your code to the server which makes it difficult to unit test and is not portable. I prefer this approach.

这篇关于获取WebSphere app Server的实例名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 23:26