views:

66

answers:

2

I would like to get the value of the Websphere variable APP_INSTALL_ROOT from a java class. How can this be done.

+2  A: 

Try this site:

http://www.slightlytallerthanaverageman.com/2007/04/02/access-websphere-variables-in-j2ee-applications/

IcyBlueRose
Thanks for linking to my blog!
craigforster
+1  A: 

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"});
knx