Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Strategies for WebLogic Domain Configuration

Scripting Options, part 2

In my previous article (WLDJ, Vol. 3, issue 8), I gave you a detailed overview of the different strategies available for domain creation and configuration and evaluated manual and templating options. In this article, I employ tools like WLShell, WebLogic Scripting Tool, Silent Scripts, and Ant for domain configuration. These tools leverage simple, high-level scripting languages.

Note: This article relies heavily on the common steps such as Domain Creation, Database Configuration, and Verifying the Domain Configu-ration described in part 1.

Scripting Language

There are many questions regarding the structure and semantics of the scripting language. How do you write comments? What, if any, is the line separator? What data-types does the language support? Does the language have variables and assignments? How do you perform query and navigation? How do you invoke behavior (i.e., methods)? Is there support for branching and looping? Fortunately, many scripting alternatives exist for domain configuration. Let's look at some of them.

According to the WLShell Web site, "WLShell is a shell for WebLogic." WLShell uses a very simple scripting language to provide access to JMX Mbeans, and a familiar file and directory navigation model to navigate MBeans.

Installation of WLShell is easy. Download the appropriate installer and execute it. Follow the installer steps and complete the installation.

WLShell scripting language supports single-line comments. The comment character is a hash-mark (#). Everything from # is commented out. There is no special end-of-line character. The echo command is either print or echo.

WLShell uses the familiar concept of directories and files for navigating the WebLogic Server instance where the MBeans correspond to directories and the attributes of MBeans correspond to files. Hence, navigation happens with recognizable commands like cd and ls. The command to create an MBean is md and the command to delete an object is rd. For example, in order to create a connection pool named semJDBCConnectionPool, execute the following command:

md /JDBCConnectionPool/semJDBCConnectionPool

What if the name contains a forward slash? The forward slash is escaped by using an additional forward slash. For example, to create a data source named jdbc/semJDBCDataSource, execute the following command:

md /JDBCTxDataSource/jdbc//semJDBCDataSource

Setting the variable attribute of an object is done with the set command. To set a variable of the boolean type, invoke set variable-name true-or-false. For example, to set StdoutDebugEnabled variable to true, invoke the following command:

set StdoutDebugEnabled true

To set a variable of integer type, invoke set variable-name integer-value. For example, to set StdoutSeverityLevel to 64, invoke the following command:

set StdoutSeverityLevel 64

To set a variable of string type, invoke set variable-name "string-value." For example, to set URL to jdbc:pointbase:server://localhost:9093/workshop, invoke the following command:

set URL "jdbc:pointbase:server://localhost:9093/workshop"

Setting variables of primitive types is easy, but how do you set a variable of java.util.Properties type? To set a variable of java.util.Properties type, use the special syntax. Invoke set variable-name (java.util.Properties) "name=value pairs separated by semicolon." For example, to set the properties for the connection pool, use the following:

set Properties (java.util.Properties)

So far, I have examined how to set variables of types boolean, int, String, and Properties. How do you set a variable of another MBean type? Just invoke set variable-name path-to-the-mbean. For example, to set the connection pool property of the JMS JDBC store, invoke the following command:

set ConnectionPool /JDBCConnectionPool/semJDBCConnectionPool

By executing the ls command, WLShell not only lists attributes that can be get or set, but also operations that can be invoked. How do you execute an operation? Using a special command called invoke. The syntax for the invoke command is: invoke method-name parameter-list-separated-by-space. For example, deploy the connection pool to the server, using the following command:

invoke addTarget /Server/$server

In the above example, the method name is addTarget. The method takes one parameter, the MBean of the server.

Deploying an application with WLShell is involved. Get a reference to /Deployer-Runtime/DeployerRuntime instance and create an instance to hold the deployment data. Associate the data with the server, and activate the application.

WLShell can be used in the script mode as well as in the interactive mode. In the interactive mode, a WLShell session is created and connected to a running WebLogic Server instance. Changes are made to the WebLogic Server instance by invoking commands in the WLShell session. To launch WLShell in interactive mode, execute the following command:


In the script mode, a script of WLShell commands is created and executed. The script can be created once and executed any number of times later to set up similar domains. The syntax to execute a script is wlsh -f script-file-name. To create the sample domain using script, execute the following command:

%wlsh -f sem_domain_wlshell.txt

In the above example, sem_domain_wlshell.txt file contains WLShell statements to configure the domain.

Before executing the WLShell script, configure an empty WebLogic Workshop domain by following the steps in the Domain Creation section using SEMDomain-WLShell as the Configuration Name. Setup the database instance by following the steps in the Database Configuration section. In order to run WLShell, just verify that wlshell/bin directory is available in the PATH environment variable. Now, execute the script:

wlsh -f sem_domain_wlshell.txt

Verify that the configuration is correct by running the tests as described in the Verifying the Domain Configuration section.

WLShell supports converting an existing config.xml file into WLShell script and commands via c2w command. WLShell supports working in off-line mode and connecting to config.xml instead of the running server. However, the implementation is not feature complete. For example, creation of a connection pool in the off-line mode results in a "feature not implemented" message.

WebLogic Scripting Tool (WLST)
WLST uses Jython as its scripting language. The Jython site states, "Jython is an implementation of high-level, dynamic, object-oriented language Python written in 100% Java, and seamlessly integrates with the Java platform." Instead of reinventing the wheel, WLST makes a very smart decision regarding the scripting infrastructure. WLST leverages the powerful scripting language of Jython.

Here are the installation instructions:

  • Download WLST (wlsScripting.zip) file and unzip the file (e.g., c:\WLST). The wlsScripting.zip file contains wlst_doc.pdf file. The wlst_doc.pdf contains all the details about WLST such as installation, configuration, and execution. Refer to the References section for detailed instructions on downloading and installing WLST.

Here are the configuration instructions for WLST:

  • Set the weblogic.jar in the CLASSPATH by executing setWLSEnv (e.g., %WLS_HOME%\server\bin\setWLSEnv.cmd).
  • Set wlst.jar in the CLASSPATH.
  • Set jython.jar in the CLASSPATH.
  • Verify that WLST is working by executing java weblogic.WLST. This executes WLST in the interactive mode.

Refer to the wlst_doc.pdf file for detailed instructions on configuring WLST.

WLST can be used in script mode as well as in interactive mode. In the interactive mode, a WLST session is created in offline mode. In this mode, WLST is not connected to a running instance of WebLogic Server. Once WLST is connected to a running WebLogic Server instance changes are made to the WebLogic Server instance by invoking commands in WLST session. In the script mode, a script of WLST commands is created and executed. Just as in the interactive mode, the script contains Jython statements. The script file is a Jython file. The script can be created once and executed any number of times later to setup similar domains.

To invoke WLST in interactive mode, invoke the following command:

java weblogic.WLST

To invoke WLST in script mode, pass in the name of the script. For example:

java weblogic.WLST sem_domain_wlst.py

Do not execute the above commands yet. At the end of this section, you will do additional setup and then execute the WLST script.

The following are the quick and basic notes on Python (and Jython). Specifying an end of statement character (;) is optional unless multiple statements are specified on a single line. The comment character is hash mark (#). All the characters from # onwards on a single line are considered part of the comment. The echo command is print. Strings can be passed in either single quotes (') or double-quotes (").

WLST uses the familiar concept of directories and files for navigating the MBeans. Hence, navigation happens with recognizable commands like cd and ls. However, every command is a function. Therefore, the commands look like cd('Servers/cgServer') and ls(). WLST defines a very special variable named cmo for the current managed object. Initially, cmo is assigned to the root. The value of cmo changes as you navigate the MBeans. In file system parlance, the value of cmo is the current working directory. Execute ls('a') to find attributes whose value can be changed. Prefix the name of the attribute with the word set to change the value of the attribute. For example, to change the value of attribute StdoutSeverityLevel to 64, invoke the following method: setStdoutSeverityLevel(64). However, on what object should the setStdoutSeverityLevel(64) method be invoked? Of course, cmo:


The other option is to assign cmo to a variable. The variable can later be used at any time throughout the current session. For example:

cgServer = cmo

Suppose you want to set StdDebugEnabled value to true. However, neither Python nor Jython supports the boolean type. Fortunately, the integer equivalents, 1 for true and 0 for false, can be used. Therefore, set the value of StdDebugEnabled to true as follows:


How do you create resources such as JDBC connections pools and JMS queues? Use WLST's built-in create() method. The create() method accepts two parameters. The first parameter is the name of the resource, whereas the second parameter is the type of resource. For example, to create a JDBC connection pool with semJDBCConnectionPool as its name, execute the following command:


Note: There is also a corresponding delete() method that works similarly.

WLST provides a special method named makePropertiesObject() to create a properties object out of a string of name and value pairs separated via semicolon. Therefore, set the properties of a JDBC connection pool as follows:

semCPProperties =

Deploying the newly created resource, such as the connection pool, to the server is easy. Invoke the addTarget() method of the source as follows:


Deploying an application is very easy with WLST using the deploy() method. The deploy() method takes three parameters. The first parameter is the name of the application. The second parameter is the path to the location of the EAR file. The third parameter is the target or the server name. The following is the example of the deploy() method:


Before executing the WLST script, configure an empty WebLogic Workshop domain by following the steps in the Domain Creation section using SEMDomain-WLST as the Configuration Name. Setup the database instance by following the steps in the Database Configuration section. Now, execute the script:

java weblogic.WLST sem_domain_wlst.py

Restart the WebLogic Server instance and verify that the configuration is correct by running the tests as described in the Verifying the Domain Configuration section.

Is it possible to reverse engineer an existing domain into a WLST script? Absolutely. Using the configuretoscript() command, the contents of an existing domain are converted into a WLST script file. Use this feature to quickly incorporate WLST into your current process.

Silent Scripts

A silent script consists of statements that are executed by the configuration wizard in silent mode. The silent script uses a very simple language. The statements are terminated by semicolons (;). The language supports Java-style comments. Double forward slash (//) is used to comment to the end of the line whereas /* ? */ is used to comment sections. The language has no concept of data-types; everything is a string enclosed in double quotes. For example, to set boolean or integer types just enclose the value in double quotes, as shown below:

set cgServer.StdoutDebugEnabled "true";
set cgServer.StdoutSeverityLevel "64";

The simple types can be converted to their string equivalents, but what about objects? In the case of objects the name of the object is used. For example, to set the error destination for a queue:

set aq.ErrorDestination "SEMAppWeb.queue.AsyncDispatcher_error";

There is no support for branching and looping. There is no navigation. The structure of the silent script file is flat. The language does support variables. A variable can be assigned upon either creating a new object or finding a preexisting object. For example, a variable assignment on finding a preexisting object:

find Server "cgServer" as cgServer;

And, a variable assignment on creating a new object:

create JDBCConnectionPool "semJDBCConnectionPool" as semCP;

The script uses special syntax to deploy resources to their targets, i.e., calling the addTarget() method of an MBean. The special syntax is assign <resource type> "<resource name>" to Target "<server name>";. For example, to deploy semJDBCConnectionPool to cgServer use the following syntax:

assign JDBCConnectionPool "semJDBCConnectionPool" to Target "cgServer";

The silent script enables domain creation very nicely. Therefore, you can either create the domain using the Configuration Wizard as described in the Domain Configuration section or use the silent script. I will illustrate domain creation with a silent script. The sem_domain_silent_create.txt script illustrates domain creation. The silent script reads Basic WebLogic Workshop Domain template and creates a domain. But, how do you invoke the script? The syntax to invoke the silent script is:

> %BEA_HOME%/weblogic81/common/bin/config.cmd -mode=silent -silent_script=full path to script file
-log=full path to the log file

Now, create the domain using the sem_domain_silent_create.txt script.

The -log flag is optional, but highly recommended. When there are errors, the messages logged to the console are very terse, but the complete exception trace is logged to the log file. The log file is immensely important in debugging silent configuration scripts.

Please note that in sem_domain_silent_create.txt file, if the WebLogic user is not assigned a password, the script will fail. Also, newly created users by default are assigned to group Administrators. Therefore, upon creating a user system, the user system belongs to group Administrators. If the script tries to write a domain to a location that already exists, the script fails. In order to replace a preexisting domain, set the OverwriteDomain variable to true.

Next, set up the database as described in the Database Configuration section. Now, shut down the server if the server is running. Configure the server by executing the sem_domain_silent_config.txt script. Be aware that the order of setting driverName and URL is important. Otherwise, the creation of the connection pool fails!

Note the update domain; command at the end of sem_domain_silent_config.txt script. This command is very important. Without it, changes made to the domain will not be committed, and the domain will not be changed!

How do you deploy the application while configuring the domain using the silent script (Note: the server is not running)? Create a custom template that contains the application. The custom template is a JAR file that contains the EAR file, the relevant section of config.xml that will be merged into current config.xml, and some metadata in the template-info.xml file. In the silent script, add the template using the add Template ? command. Adding at least one template when updating the domain is necessary, otherwise the changes made to the domain are not persisted! A common technique, if you do not have your own template, is to use the DefaultWebApp template.

Verify that the configuration is correct by running the tests described in the Verifying the Domain Configuration section.

Special Ant Tasks

Apache Ant is an invaluable tool for building and deploying applications. An Ant file is an XML file that contains many targets. The targets invoke tasks. WebLogic ships special tasks such as wlconfig and wldeploy. The wlconfig Ant task helps with domain configuration. The wldeploy Ant task helps with application deployment.

WebLogic Server installation also includes Ant. Ant is automatically set up when setting up the environment by executing the setWLSEnv (bat or sh) script. The taskdefs for wlconfig and wldeploy are not required if this version of Ant is used.

The language of the Ant file is XML. Therefore, language specifics like comments are XML comments. Other features, like the echo are Ant-specific.

The wlconfig task contains nested elements such as query and create. The query element is used to find preexisting MBeans, whereas the create element is used to create new MBeans. Both query and create support get and set elements to get and set MBean attributes. The syntax for the set attribute is: <set attribute="MbeanAttributeName" value="NewValue"/>. All attribute values, regardless of type, are enclosed in double quotes and passed in as string. Consider setting the MBean attribute StdoutDebugEnabled value of type boolean to true.

<set attribute="StdoutDebugEnabled" value="true"/>

Similarly, consider setting the MBean attribute StdoutSeverityLevel value of type integer to 64.

<set attribute="StdoutSeverityLevel" value="64"/>

Once an object is queried, the object can optionally be set as an Ant property that is available throughout the file. For example, the server is queried and set into cgServer property. Later, in the build file, the cgServer property is utilized to target resources to the server.

Note: The wlconfig does not currently support the invoke command. Therefore, for example, targets are set as attributes instead of invoking the addTarget operation.

The wldeploy Ant task is used to deploy and undeploy the application. The wldeploy task takes actions such as deploy, undeploy, redeploy, cancel, start, stop, and distribute.

In order to execute the included Ant file, first create the domain by following the steps described in the Domain Creation section, giving a meaningful name like SEMDomain-Ant as the Configuration Name.

Note: Since the name of the domain is used in the Ant file, either use SEMDomain-ANT as the domain name or change the Ant file to match your domain name. Start the WebLogic server instance and use the steps described in the Database Configuration to configure the database. Launch a new command or shell window and execute the %WLS_HOME%/server/bin/setWLSEnv (cmd or sh) file to set up the environment. Execute the Ant using the following command:

ant -v -f sem_domain_ant_config.xml

Run the tests as described in Verifying the Domain Configuration section.

The verbose (-v) option to the Ant command displays the MBean commands issued to the server. The information is very valuable in debugging and troubleshooting.

An Ant file encourages very modular development of the automated script. Each individual resource is created and configured using a separate target. Using Ant dependencies, the all target calls the individual Ant targets and does the complete configuration. Ant encourages the creation of a clean target. The order of dependencies in the clean target is opposite that of the all target.

Conclusion: Choices, Choices, and More Choices

This article described domain configuration using WLShell, WLST, Silent Scripts, and Ant tasks. These tools employ simple and powerful high-level scripting languages. Whereas WLShell uses a custom scripting language, WLST leverages Jython. Once a domain configuration script is created, setting up another identical domain is a simple matter of executing the script. Scripting domain configuration is the way to go for automating domain configuration.


  • To discuss the article and ask questions start here: www.bartssandbox.com. Free membership is required.
  • WLShell: www.wlshell.net/
  • Download WLST from BEA dev2dev code library: http://dev2dev.bea.com/codelibrary/code/wlst.jsp
  • More Stories By Prakash Malani

    Prakash Malani has extensive experience in architecting, designing, and developing object-oriented software and has done software development in many application domains such as entertainment, retail, medicine, communications, and interactive television.He practices and mentors leading technologies such as J2EE, UML, and XML. Prakash has published various articles in industry- leading publications.

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

    IoT & Smart Cities Stories
    Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities - ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups.
    DXWorldEXPO LLC announced today that Telecom Reseller has been named "Media Sponsor" of CloudEXPO | DXWorldEXPO 2018 New York, which will take place on November 11-13, 2018 in New York City, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
    In his keynote at 18th Cloud Expo, Andrew Keys, Co-Founder of ConsenSys Enterprise, will provide an overview of the evolution of the Internet and the Database and the future of their combination – the Blockchain. Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life ...
    Chris Matthieu is the President & CEO of Computes, inc. He brings 30 years of experience in development and launches of disruptive technologies to create new market opportunities as well as enhance enterprise product portfolios with emerging technologies. His most recent venture was Octoblu, a cross-protocol Internet of Things (IoT) mesh network platform, acquired by Citrix. Prior to co-founding Octoblu, Chris was founder of Nodester, an open-source Node.JS PaaS which was acquired by AppFog and ...
    The Founder of NostaLab and a member of the Google Health Advisory Board, John is a unique combination of strategic thinker, marketer and entrepreneur. His career was built on the "science of advertising" combining strategy, creativity and marketing for industry-leading results. Combined with his ability to communicate complicated scientific concepts in a way that consumers and scientists alike can appreciate, John is a sought-after speaker for conferences on the forefront of healthcare science,...
    "The Striim platform is a full end-to-end streaming integration and analytics platform that is middleware that covers a lot of different use cases," explained Steve Wilkes, Founder and CTO at Striim, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
    The deluge of IoT sensor data collected from connected devices and the powerful AI required to make that data actionable are giving rise to a hybrid ecosystem in which cloud, on-prem and edge processes become interweaved. Attendees will learn how emerging composable infrastructure solutions deliver the adaptive architecture needed to manage this new data reality. Machine learning algorithms can better anticipate data storms and automate resources to support surges, including fully scalable GPU-c...
    Predicting the future has never been more challenging - not because of the lack of data but because of the flood of ungoverned and risk laden information. Microsoft states that 2.5 exabytes of data are created every day. Expectations and reliance on data are being pushed to the limits, as demands around hybrid options continue to grow.
    Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
    The explosion of new web/cloud/IoT-based applications and the data they generate are transforming our world right before our eyes. In this rush to adopt these new technologies, organizations are often ignoring fundamental questions concerning who owns the data and failing to ask for permission to conduct invasive surveillance of their customers. Organizations that are not transparent about how their systems gather data telemetry without offering shared data ownership risk product rejection, regu...