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
Thanks
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 …
and add a variable like this …
You can then access the value in your code as …
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.