Home > Oracle MiddleWare, WebLogic > Java Sample To List WebLogic Deployments (WARs, EARs)

Java Sample To List WebLogic Deployments (WARs, EARs)


API for weblogic server http://download.oracle.com/docs/cd/E11035_01/wls100/javadocs/index.html?weblogic/deploy/api/spi/package-summary.html

Make sure you don’t have jrmp.jar and jrmpclient.jar in the class path while running this program.

Following is the output of the program, which was run on my WebLogic Server.


Get Domain:IDMDomain_112
Total Modules deployed in WebLogic are:57
Target Module ID={Target=AdminServer, WebLogicTargetType=server, Name=DMS Application#11.1.1.1.0}
Target Module ID={Target=AdminServer, WebLogicTargetType=server, Name=ASConfigManagement}
Target Module ID={Target=AdminServer, WebLogicTargetType=server, Name=oracle.bi.composer#11.1.1@0.1}
Target Module ID={Target=AdminServer, WebLogicTargetType=server, Name=oracle.jrf.system.filter}
Target Module ID={Target=AdminServer, WebLogicTargetType=server, Name=adf.oracle.businesseditor#1.0@11.1.1.2.0}
Target Module ID={Target=AdminServer, WebLogicTargetType=server, Name=oracle.adf.management#1.0@11.1.1.2.0}
Target Module ID={Target=AdminServer, WebLogicTargetType=server, Name=adf.oracle.domain.webapp#1.0@11.1.1.2.0}
...
...

package com.weblogic.test;
import javax.enterprise.deploy.shared.ModuleType;
import javax.enterprise.deploy.spi.Target;
import javax.enterprise.deploy.spi.TargetModuleID;
import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
import javax.enterprise.deploy.spi.exceptions.TargetException;
import weblogic.deploy.api.spi.DeploymentOptions;
import weblogic.deploy.api.spi.WebLogicDeploymentManager;
import weblogic.deploy.api.tools.SessionHelper;

/**
 * This program lists all applications deployed in the weblogic server.
 *
 * Note: Make sure you don't have jrmp.jar and jrmpclient.jar while running this
 * code.
 *
 * @author karun.chennuri
 *
 */
public class WebLogicAppDeployment {</pre>
<pre style="padding-left: 30px;"> private final static String protocol = "t3";
 private final static String hostName = "localhost";
 private final static String portString = "7001";
 private final static String adminUser = "weblogic";
 private final static String adminPassword = "Welcome1";

public static void main(String args[]) throws Exception {
 WebLogicAppDeployment deployTest = new WebLogicAppDeployment();
 deployTest.print(
 "::::::::::Start of WebLogicAppDeployment::::::::::::::::", 0);
 boolean flag = deployTest.getDeploymentList();
 deployTest.print("Is DeploymentList retrieval Success or Failure? ="
 + flag, 0);
 deployTest.print(
 "::::::::::End of WebLogicAppDeployment::::::::::::::::", 0);
}

/**
* Gets DeploymentList
*
* @return
*/

private boolean getDeploymentList() {
 try {
 // get WebLogicDeploymentManager instance
 WebLogicDeploymentManager deployManager = getDeploymentManager();
 // get all targets i.e. weblogic server domains
 Target targets[] = getTargetsList(deployManager);
 // get list of deployments on the weblogic domain i.e. AdminServer
 // etc
 listAllDeployments(deployManager, targets);
 } catch (Exception e) {
 print(e.getMessage(), 2);
 e.printStackTrace();
 return false;
 }
 return true;
}

/**
* Get WebLogicDeploymentManager instance
*
* @return
*/

private WebLogicDeploymentManager getDeploymentManager() {
 WebLogicDeploymentManager deployManager = null;
 try {
 deployManager = SessionHelper.getRemoteDeploymentManager(protocol,
 hostName, portString, adminUser, adminPassword);
 } catch (DeploymentManagerCreationException dmce) {
 print(dmce.getMessage(), 2);
 dmce.printStackTrace();
 }
 return deployManager;
}

/**

* Get List of Targets i.e. list of AdminServer and Managed Servers of
* WebLogic target
*
* @param deployManager
* @return
* @throws Exception
*/

private Target[] getTargetsList(WebLogicDeploymentManager deployManager)
throws Exception {
 Target tempTarget[] = new Target[0];

 if (deployManager != null) {
 print("WebLogicDeploymentManager: " + deployManager, 0);
 DeploymentOptions options = new DeploymentOptions();
 print("DeploymentOptions: " + options, 0);
 Target targets[] = deployManager.getTargets();
 print("------------Start Iterate over Targets List-----------", 0);
 for (int i = 0; i < targets.length; i++) {
 print("Target:" + targets[i], 0);
 }
 print("------------End Iterate over Targets List-----------", 0);
 return targets;
 }
 return tempTarget;
}

/**
* Get List of all the deployments. You may define the type of the module
* here. ModuleType are CAR, EJB, WAR, EAR, RAR.
*
* @param deployManager
* @param targets
* @throws TargetException
*/
private void listAllDeployments(WebLogicDeploymentManager deployManager,
 Target targets[]) throws TargetException {
 if (deployManager != null && targets.length > 0) {
 print("Get Domain:" + deployManager.getDomain(), 0);
 TargetModuleID targetModuleID[] = deployManager
 .getAvailableModules(ModuleType.WAR, targets);
 printDeployment(targetModuleID);
 } else {
 print(
 "WebLogicDeploymentManager is either empty or targets are empty.Please check",
 1);
 }

}

/**
* iterate over deployment list
*
* @param targetModuleID
*/
private void printDeployment(TargetModuleID targetModuleID[]) {
 print("Total Modules deployed in WebLogic are:"+targetModuleID.length,0);
 if (targetModuleID.length > 0) {
 for (int j = 0; j < targetModuleID.length; j++) {
 print("Target Module ID=" + targetModuleID[j], 0);
 }
 } else {
 print("TargetModuleID is Empty!", 1);
 }
}

/**
* Just a Sysout statement
*
* @param str
* @param type
*/
private void print(String str, int type) {
 if (type == 1) {
 str = "[WARNING]:" + str;
 } else if (type == 2) {
 str = "[ERROR]:" + str;
 }
 System.out.println(str);
}
}
Advertisements
  1. Abdurrahman
    April 8, 2013 at 3:20 PM

    Thanks it was so helpfull

    Like

  2. Naveen
    August 11, 2014 at 12:31 PM

    Thru this approach, how to read the contents of Manifest.MF of all the ears,wars and jars deployed in the weblogic server

    Like

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: