Access to Websphere 6.1 Variables

I would like to get the value of the Websphere APP_INSTALL_ROOT variable from the java class. How can I do that.

+2
source share
4 answers

From the IBM Information Center:

You can use WebSphere variables to provide settings for any string of data type attributes that are contained in the product configuration files.

Because applications cannot directly access WebSphere variables, if you define a WebSphere variable inside the application, an error message such as "Unknown variable" is generated. If you are referencing the WebSphere variable from within the application, include the following method in the application to extend the string using the WebSphere variable:

private String expandVariable(String s) throws javax.management.JMException { com.ibm.websphere.management.AdminService as = com.ibm.websphere.management.AdminServiceFactory.getAdminService (); String server = as.getProcessName(); java.util.Set result = as.queryNames(new javax.management.ObjectName("*:*,type=AdminOperations,process=" + server), null); return (String)as.invoke((javax.management.ObjectName) result.iterator().next(),"expandVariable",new Object[] {"${"+s+"}"}, new String[] {"java.lang.String"}); 
+2
source

Another way to get the value of the Websphere variable in your application is to define a regular environment variable in the WAS console that points to your Websphere variable:

  • Define the variable websphere someVariable = someValue
  • Go to (something like) Servers โ†’ Server Types โ†’ Websphere Server Application โ†’ YOUR_SERVER โ†’ Java and Process Control โ†’ Process Definition โ†’ Java Virtual Machine โ†’ Custmo Properties
  • Define a new variable someVariable = $ {someVariable}

Now navigate to the variable as System.getProperty ("someVariable")

+2
source

Sorry, I can not write a comment.

I get the same variable surrounded by $ {}. Security configuration not configured. Any hints? - xain

You must restart the server after creating the variables.

0
source

Source: https://habr.com/ru/post/1436384/


All Articles