Démarrage d'une application par programmation
Vous pouvez démarrer une application via la console d'administration, l'outil wsadmin ou la programmation. Cet exemple permet de démarrer une application par programmation.
Avant de commencer
Avant de pouvoir démarrer une application sur WebSphere Application Server, vous devez installer cette dernière.
Pourquoi et quand exécuter cette tâche
Procédez comme suit pour démarrer une application par programmation.
Procédure
- Connectez le client d'administration à WebSphere Application Server.
- Créez le proxy de gestion d'applications.
- Appelez la méthode startApplication sur le proxy en transmettant le nom de l'application et éventuellement la liste des cibles sur lesquelles démarrer l'application.
Résultats
Exemple
L'exemple suivant explique comment démarrer une application en suivant la procédure précédente. Certaines instructions sont présentées sur plusieurs lignes à des fins d'affichage.
//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)