通过编程启动应用程序
您可以通过管理控制台、wsadmin 工具或编程来启动应用程序。使用此示例,通过编程来启动应用程序。
开始之前
您必须首先在 WebSphere® Application Server 上安装了应用程序,才能启动该应用程序。
关于此任务
执行以下各项任务,从而通过编程来启动应用程序。
过程
- 将管理客户机连接到 WebSphere Application Server。
- 创建应用程序管理代理。
- 通过传递应用程序名以及传递启动此应用程序的目标的列表(后者是可选的)对代理调用 startApplication 方法。
结果
示例
以下示例显示如何根据先前列示的步骤启动应用程序。为了便于打印,某些语句被拆分为几行。
//Do a get of the administrative client to connect to
//WebSphere Application Server.
AdminClient client = ...;
String appName = "myApp";
Hashtable prefs = new Hashtable();
// Use the AppManagement MBean to start and stop applications on all or some targets.
// The AppManagement MBean is on the deployment manager in the WebSphere Application Server Network Deployment product.
// Query and get the AppManagement MBean.
ObjectName on = new ObjectName ("WebSphere:type=AppManagement,*");
Iterator iter = client.queryNames (on, null).iterator();
ObjectName appmgmtON = (ObjectName)iter.next();
//Start the application on all targets.
AppManagement proxy = AppManagementProxy.getJMXProxyForClient(client);
String started = proxy.startApplication(appName, prefs, null);
System.out.println("Application started on folloing servers: " + started);
//Start the application on some targets.
//String targets = "WebSphere:cell=cellname,node=nodename,
server=servername+WebSphere:cell=cellname,cluster=clusterName";
//String started1 = proxy.startApplication(appName, targets, prefs, null);
//System.out.println("Application started on following servers: " + started1)