Doug
Doug

Reputation: 390

Accessing Websphere 6.1 variables

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

Answers (4)

Fabian
Fabian

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

DagR
DagR

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:

  1. Define your websphere variable someVariable = someValue
  2. Go to (something like) Servers -> Server Types -> Websphere application servers -> YOUR_SERVER -> Java and process management -> Process definition -> Java virtual machine -> Custmo properties
  3. Define a new variable someVariable = ${someVariable}

Now access the variable as System.getProperty("someVariable")

Upvotes: 2

knx
knx

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

Related Questions