编辑应用程序

可通过管理控制台、wsadmin 工具或编程来编辑已部署应用程序。使用此示例以通过编程来编辑已部署应用程序。

开始之前

此任务假设您对 MBean 编程有基本的了解。有关 MBean 编程的信息,请参阅 MBean Java™ 应用程序编程接口 (API) 文档。 在此信息中心中,单击引用 > MBean 接口

可以在 WebSphere® Application Server 上编辑应用程序前,您必须安装该应用程序。

关于此任务

执行下列任务以编辑已部署应用程序。

过程

  1. 连接到 WebSphere Application Server
  2. 创建应用程序管理代理。
  3. 获取有关已安装应用程序的信息。
  4. 必要时处理任务数据。
  5. 保存已安装应用程序的更改。

结果

成功运行代码之后,就编辑了应用程序。

示例

以下示例显示如何根据上述步骤编辑应用程序。

import java.lang.*;
import java.io.*;
import java.util.*;
import java.lang.reflect.*;
import com.ibm.websphere.management.application.*;
import com.ibm.websphere.management.application.client.*;
import com.ibm.websphere.management.*;

import javax.management.*;

public class aa {

    public static void main (String [] args) {

        try {
             
  // Connect to WebSphere Application Server.
  String host = "localhost";
  String port = "8880";
  String target = "WebSphere:cell=cellName,node=nodeName,server=server1";

  Properties config = new Properties();
  config.put (AdminClient.CONNECTOR_HOST,  host);
  config.put (AdminClient.CONNECTOR_PORT,  port);
  config.put (AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);
  System.out.println ("Config: " + config);
     AdminClient _soapClient = AdminClientFactory.createAdminClient(config);
  
  // Create the application management proxy, AppManagement.
  AppManagement proxy = AppManagementProxy. getJMXProxyForClient (_soapClient);

  String appName = "MyApp";
// Get information for an application with name appName:
// Pass Locale information as the preference.
Hashtable prefs = new Hashtable();
 prefs.put(AppConstants.APPDEPL_LOCALE, Locale.getDefault()); 
Vector allTasks =  appMgmt.getApplicationInfo (appName, prefs, null); 

// Manipulate task data as necessary.
if (task.getName().equals ("MapRolesToUsers") && !task. isTaskDisabled()) 
{ 
       // find out column index for role and user column 
       // refer to the previous table to find the column names
       int roleColumn = -1;
       int userColumn = -1;
       String[] colNames = task.getColumnNames();
       for (int i=0; i < colNames.length; i++)
       { 
            if (colNames[i].equals ("role"))
            	roleColumn = i;
            else if (colNames[i].equals ("role.user"))
               userColumn = i; 
       } 
            
       // iterate over task data starting at row 1 as row0 is
       // column names
       String[][]data = task.getTaskData();
       for (int i=1; i < data.length; i++)
       {
            if (data[i][roleColumn].equals ("Role1")) 
            {
            	data[i][userColumn]="User1|User2";
               break;
            }
       } 
       
       // now that the task data is changed, save it back
       task.setTaskData (data);
} 

// Save changes back into the installed application:
// Set information for an application with name appName. 
// Pass Locale information as the preference.
prefs = new Hashtable();
prefs.put(AppConstants.APPDEPL_LOCALE, Locale.getDefault());
appMgmt.setApplicationInfo (appName, prefs, null, allTasks);

        }
        catch (Exception e) {
            e.printStackTrace();
        }

    }

}

指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tjmx_edit_apps
文件名:tjmx_edit_apps.html