Reputation: 390
I would like to get the value of the Websphere variable APP_INSTALL_ROOT from a java class. How can this be done.
Upvotes: 3
Views: 7337
Reputation: 31
Sorry, i can't write a comment.
I get the same variable surrounded by ${}. No security configured. Any hints? – xain
You have to restart the server after your variables creation.
Upvotes: 0
Reputation: 3100
Another way to get the value of a Websphere variable in your app is to define a regular environment variable in the WAS console pointing to your Websphere variable:
Now access the variable as System.getProperty("someVariable")
Upvotes: 2
Reputation: 340
From IBM infocenter:
You can use WebSphere variables to provide settings for any of the string 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 of an application, an error message, such as "Unknown variable," is returned. If you must reference a WebSphere variable from within an application, include the following method in the application to expand the string that uses 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"});
Upvotes: 2