Want to deploy WAR file to WAS V6.1 using JMX API(programmatically) - Websphere

This is a discussion on Want to deploy WAR file to WAS V6.1 using JMX API(programmatically) - Websphere ; Hi All, I want to deploy a WAR file to WAS v6.1 standalone server using JMX API. When I am running the java client WASJMXWARDeployer (see below code) failed status is printed on console and the following exception in server ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Want to deploy WAR file to WAS V6.1 using JMX API(programmatically)

  1. Want to deploy WAR file to WAS V6.1 using JMX API(programmatically)

    Hi All,

    I want to deploy a WAR file to WAS v6.1 standalone server using JMX API.
    When I am running the java client WASJMXWARDeployer (see below code) failed status is printed on console and the following exception in server side logs.

    +Stack Dump = AppDeploymentException: \[Error accessing the EAR file\] com.ibm.websphere.management.exception.AdminExcept ion:+
    ………
    +Caused by: org.eclipse.jst.j2ee.commonarchivecore.internal.ex ception.OpenFailureException: IWAE0006E Archive is not a valid EAR File because the deployment descriptor can not be found (case sensitive): META-INF/application.xml+

    I am attaching the sample WAR and the code and log files.

    *Please suggest me how to deploy a war file using JMX.*

    _WASJMXWARDeployer.java_
    {code}
    package jmx.websphere.deploy;

    import java.util.*;
    import javax.management.*;
    import com.ibm.websphere.management.*;
    import com.ibm.websphere.management.application.*;
    import com.ibm.websphere.management.configservice.*;

    public class WASJMXWARDeployer {
    private static final String was_host = "localhost";
    private static final String was_soap_port = "8881";
    private static final String appName = "TestSS";
    private static final String appFile = "C:/was/Test.war";

    @SuppressWarnings("unchecked")
    public static void main(String[] args) throws Exception {
    Properties wasServerProps = new Properties();
    wasServerProps.setProperty(AdminClient.CONNECTOR_H OST, was_host);
    wasServerProps.setProperty(AdminClient.CONNECTOR_P ORT, was_soap_port);
    wasServerProps.setProperty(AdminClient.CONNECTOR_T YPE, AdminClient.CONNECTOR_TYPE_SOAP);
    AdminClient adminClient = AdminClientFactory.createAdminClient(wasServerProp s);


    Session configSession = new Session();
    ConfigServiceProxy configProxy = new ConfigServiceProxy(adminClient);

    Hashtable prefs = new Hashtable();
    prefs.put(AppConstants.APPDEPL_WEB_CONTEXTROOT, appName);
    //prefs.put(AppConstants.APPDEPL_WEBMODULE_CONTEXTRO OT, appName);

    prefs.put(AppConstants.APPDEPL_PRECOMPILE_JSP, Boolean.FALSE);
    prefs.put(AppConstants.APPDEPL_DISTRIBUTE_APP, Boolean.TRUE);
    prefs.put(AppConstants.APPDEPL_USE_BINARY_CONFIG, Boolean.FALSE);
    prefs.put(AppConstants.APPDEPL_DEPLOYEJB_CMDARG, Boolean.FALSE);
    prefs.put(AppConstants.APPDEPL_FILETRANSFER_UPLOAD , Boolean.TRUE);
    prefs.put(AppConstants.APPDEPL_VALIDATE_APP, Boolean.FALSE);

    Hashtable module2Server = new Hashtable();
    ObjectName serverMBean = adminClient.getServerMBean();
    String targetServer="WebSphere:cell="
    + serverMBean.getKeyProperty("cell")
    + ",node=" + serverMBean.getKeyProperty("node")
    + ",server=" + serverMBean.getKeyProperty("process");

    module2Server.put("WEB-INF/web.xml",targetServer);
    prefs.put(AppConstants.APPDEPL_MODULE_TO_SERVER, module2Server);
    Hashtable mapWebModToVH = new Hashtable();
    mapWebModToVH.put("WEB-INF/web.xml", "default_host");
    prefs.put(AppConstants.APPDEPL_VIRTUAL_HOST, mapWebModToVH);
    prefs.put(AppConstants.APPDEPL_ARCHIVE_UPLOAD, Boolean.TRUE);

    NotificationFilterSupport filterSupport = new NotificationFilterSupport();
    filterSupport.enableType(AppConstants.Notification Type);
    MyAdminAppNotificationListener listener = new MyAdminAppNotificationListener(adminClient,
    filterSupport,
    "Install " + appName,
    AppNotification.INSTALL);
    AppManagement appManagementProxy = AppManagementProxy.getJMXProxyForClient(adminClien t);
    appManagementProxy.installApplication(appFile,appN ame, prefs, configSession.getSessionId());
    synchronized(listener){
    listener.wait();
    }
    if(listener.isSuccessful()){configProxy.save(confi gSession, false);}
    else{configProxy.discard(configSession);}
    }
    }
    {code}
    _MyAdminAppNotificationListener.java_
    {code}
    package jmx.websphere.deploy;

    import javax.management.*;
    import com.ibm.websphere.management.AdminClient;
    import com.ibm.websphere.management.application.AppNotifi cation;

    public class MyAdminAppNotificationListener implements NotificationListener{
    private AdminClient _adminClient;
    private NotificationFilterSupport _filterSupport;
    private Object _handBack;
    private ObjectName _objectName;
    private String eventTypeToCheck;
    private boolean successful = true;

    public MyAdminAppNotificationListener(AdminClient client,
    NotificationFilterSupport support, Object handBack,
    String eventTypeToCheck) throws Exception {
    super();
    _adminClient = client;
    _filterSupport = support;
    _handBack = handBack;
    this.eventTypeToCheck = eventTypeToCheck;
    _objectName = (ObjectName) _adminClient.queryNames(new ObjectName("WebSphere:type=AppManagement,*"), null).iterator().next();
    _adminClient.addNotificationListener(_objectName, this, _filterSupport, _handBack);
    }

    public void handleNotification(Notification notification, Object handback) {
    AppNotification appNotification = (AppNotification) notification.getUserData();
    if(appNotification.taskName.equals(eventTypeToChec k) &&
    (appNotification.taskStatus.equals(AppNotification .STATUS_COMPLETED)||
    appNotification.taskStatus.equals(AppNotification. STATUS_FAILED))){
    try {
    _adminClient.removeNotificationListener(_objectNam e, this);
    if(appNotification.taskStatus.equals(AppNotificati on.STATUS_FAILED)) successful = false;
    synchronized(this){
    notifyAll();
    }
    } catch (Exception e) {}
    }
    }

    public boolean isSuccessful() {
    return successful;
    }
    }
    {code}

  2. Re: Want to deploy WAR file to WAS V6.1 using JMX API(programmatically)

    I can deploy EAR files Correctly
    but when i deploy WAR files i meet the same question too
    who can tell me how to deploy war files to WAS with JMX API ?

  3. Smile Re: Want to deploy WAR file to WAS V6.1 using JMX API(programmatically)

    Hi,
    Im trying to deploy EAR file in to WLS. I think this will be help full to my task as well. Could you please mail your source code with relevant import library files .
    My email sunanda@millenniumit.com

    Thanks,
    Sunanda

+ Reply to Thread