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…

When u will try the following program to deploy your applications then please  replace “ModuleType.WAR” to ModuleType.EAR -> If u want to deploy EAR Application And Similarly  replace “ModuleType.WAR” to ModuleType.JAR -> If u want to deploy JAR (EJB)Application

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;

import javax.enterprise.deploy.shared.*;

public class ApplicationDeployment
{
     public static void main(String ar[]) throws Exception
		{
			ApplicationDeployment appDeploy=new ApplicationDeployment();
			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);

			Target targets[]=deployManager.getTargets();
			System.out.println("------------------------------------------------------------");
			System.out.println("t Application Can be Deployed in the Following targets:");
			int i=0;
			for (i=0;i<targets.length;i++)
					{
					   System.out.println("nt "+targets[i]);
				    }
			System.out.println("-----------Above We need to write our Logic to Choose the Deploy target---------nn");
			Target deployTargets[]=new Target[1];
			//SUPPOSE WE WAANT TO DEPLOY IT ON AdminServer ...
			deployTargets[0]=targets[0];

            //-------------DEPLOYING FIRST APPLICATION-------------//
			String applicationDisplayName="FirstEARApplication";
			options.setName(applicationDisplayName);
			ProgressObject processStatus=deployManager.distribute(deployTargets, new File("FirstEAR.ear"), null,options);
			processStatus=deployManager.deploy(deployTargets, new File("FirstEAR.ear"), null,options);
			DeploymentStatus deploymentStatus=processStatus.getDeploymentStatus() ;
			System.out.println("nnt For FirstEAR.ear DeploymentStayus.getState(): "+deploymentStatus.getState() +"nn");

			System.out.println("Sleeping for atleast 5-Seconds. Sothat the Deployment Activation gets Completed Successfully.");
			Thread.sleep(5000);

            //-------------DEPLOYING SECOND APPLICATION-------------//
			deployManager=null;
			deployManager=SessionHelper.getRemoteDeploymentManager( protocol,hostName,portString,adminUser,adminPassword);
			applicationDisplayName="SecondEARApplication";
			options.setName(applicationDisplayName);
			processStatus=deployManager.distribute(deployTargets, new File("SecondEAR.ear"), null,options);
			Thread.sleep(5000);
			processStatus=deployManager.deploy(deployTargets, new File("SecondEAR.ear"), null,options);
			deploymentStatus=processStatus.getDeploymentStatus() ;
			System.out.println("nnt For SecondEAR.ear DeploymentStayus.getState(): "+deploymentStatus.getState() +"nn");

		}
}

(Based on the comment http://middlewaremagic.com/weblogic/?p=483#comment-4189 we have updated the JMX Deployment Code)

In the above Updated JMX Code You will get following kind of Output:

C:JMX_Notification>javac ApplicationDeployment.java
Note: ApplicationDeployment.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

C:JMX_Notification>java ApplicationDeployment

         WebLogicDeploymentManager: weblogic.deploy.api.spi.deploy.WebLogicDeploymentManagerImpl@1dd7ed

         DeploymentOptions: {isRetireGracefully=true,isGracefulProductionToAdmin=false,isGracefulIgnoreSessions=false,rmiGracePeriod=-1,reti
reTimeoutSecs=-1,undeployAllVersions=false,archiveVersion=null,planVersion=null,isLibrary=false,libSpecVersion=null,libImplVersion=null,stag
eMode=null,clusterTimeout=3600000,altDD=null,altWlsDD=null,name=null,securityModel=null,securityValidationEnabled=false,versionIdentifier=nu
ll,isTestMode=false,forceUndeployTimeout=0,defaultSubmoduleTargets=true,timeout=0deploymentPrincipalName=null}
------------------------------------------------------------
         Application Can be Deployed in the Following targets:

         AdminServer/server

         MyJMSServer/JMS server
-----------Above We need to write our Logic to Choose the Deploy target---------

<Jun 4, 2011 6:37:17 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating distribute operation for application, FirstEARApplication
 [archive: C:JMX_NotificationFirstEAR.ear], to AdminServer .>
<Jun 4, 2011 6:37:41 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, FirstEARApplication [ar
chive: C:JMX_NotificationFirstEAR.ear], to AdminServer .>

         For FirstEAR.ear DeploymentStayus.getState(): running

Sleeping for atleast 5-Seconds. Sothat the Deployment Activation gets Completed Successfully.
<Jun 4, 2011 6:38:14 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating distribute operation for application, SecondEARApplicatio
n [archive: C:JMX_NotificationSecondEAR.ear], to AdminServer .>
<Jun 4, 2011 6:38:19 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, SecondEARApplication [a
rchive: C:JMX_NotificationSecondEAR.ear], to AdminServer .>

         For SecondEAR.ear DeploymentStayus.getState(): running

<Jun 4, 2011 6:38:21 PM IST> <Warning> <JNDI> <BEA-050001> <WLContext.close() was called in a different thread than the one in which it was
created.>
<Jun 4, 2011 6:38:21 PM IST> <Warning> <JNDI> <BEA-050001> <WLContext.close() was called in a different thread than the 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.