Hi,

Jay SenSharma

Jay SenSharma

Here is a Simple JMX code to deploy our applications on WebLogic Server. This JMX Code uses some very important WLS Deployment API like:¬†WebLogicDeploymentManager, SesionHelper, DeploymentOptions, ¬†TargetModuleID, ProgressObject etc…

Note: To deploy Applications using JMX u can refer to: http://middlewaremagic.com/weblogic/?p=483

Here is a Simple Code which demeontrate ..How we can Undeploy an Application Deployed on WebLogic Server using Java Methods…We Need to Use JMX Api to do this using Java…

ApplicationUndeployment.java

import java.io.*;
import weblogic.deploy.api.tools.*;  //SesionHelper
import weblogic.deploy.api.spi .*;  //WebLogicDeploymentManager
import weblogic.deploy.api.spi.DeploymentOptions;
import javax.enterprise.deploy.spi.TargetModuleID;
import javax.enterprise.deploy.spi.status.ProgressObject;
import javax.enterprise.deploy.spi.status.DeploymentStatus;
import javax.enterprise.deploy.shared.ModuleType;
import javax.enterprise.deploy.spi.Target;

public class ApplicationUndeployment
{
public static void main(String ar[]) throws Exception
{
ApplicationUndeployment appDeploy=new ApplicationUndeployment();
String protocol="t3";
String hostName="localhost";
String portString="7001";
String adminUser="weblogic";
String adminPassword="weblogic";

WebLogicDeploymentManager deployManager=SessionHelper.getRemoteDeploymentManager( protocol,hostName,portString,adminUser,adminPassword);
System.out.println("nt WebLogicDeploymentManager: "+deployManager);
DeploymentOptions options = new DeploymentOptions();
System.out.println("nt DeploymentOptions: "+options);

TargetModuleID[] targetModuleIDs=deployManager.getAvailableModules(ModuleType.EAR, deployManager.getTargets());
System.out.println("targetModuleIDs length: "+targetModuleIDs.length);
for(int i=0;i<targetModuleIDs.length;i++)
{
System.out.println("nntUNDEPLOYING------- targetModuleIDs["+i+"]: "+targetModuleIDs[i]);
ProgressObject processStatus=deployManager.undeploy(new TargetModuleID[]{targetModuleIDs[i]});
DeploymentStatus deploymentStatus=processStatus.getDeploymentStatus() ;
System.out.println("UnDeploymentStayus.getMessage(): "+deploymentStatus.getMessage() );
}
}

OUTPUT:
C:DELETEJMX_Deploy>java ApplicationUndeployment

WebLogicDeploymentManager: weblogic.deploy.api.spi.deploy.WebLogicDeploymentManagerImpl@35e6e3

DeploymentOptions: {isRetireGracefully=true,isGracefulProductionToAdmin=false,isGracefulIgnoreSessions=false,rmiGracePeriod=-1,retireTimeoutSecs=-1,undeployAllVersions=false,archiveVersion=null,planVersion=null,isLibrary=false,libSpecVersion=null,libImplVersion=null,stageMode=null,clusterTimeout=3600000,altDD=null,altWlsDD=null,name=null,securityModel=null,securityValidationEnabled=false,versionIdentifier=null,isTestMode=false,forceUndeployTimeout=0,defaultSubmoduleTargets=true,timeout=0deploymentPrincipalName=null}         targetModuleIDs length: 2
UNDEPLOYINF------- targetModuleIDs[0]: {Target=AdminServer, WebLogicTargetType=server, Name=SecondWebAppEar}
<Jan 15, 2010 12:25:25 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating undeploy operation for application,
SecondWebAppEar [archive: null], to AdminServer .>
UnDeploymentStayus.getMessage(): null

UNDEPLOYING------- targetModuleIDs[1]: {Target=AdminServer, WebLogicTargetType=server, Name=wls-commonslogging-b
ridge#1.0@1.1}
<Jan 15, 2010 12:25:26 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating undeploy operation for application,
wls-commonslogging-bridge#1.0@1.1 [archive: null], to AdminServer .>
UnDeploymentStayus.getMessage(): weblogic.management.ManagementException: [Deployer:149164]The domain edit lock is owned
by another session in exclusive mode - hence this deployment operation cannot proceed.
<Jan 15, 2010 12:25:27 PM IST>

<Warning> <JNDI> <BEA-050001> <WLContext.close() was called in a different thread than th
e one in which it was created.>

.
.
Thanks
Jay SenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.