easy, elegant and effective code…

This is a sample WLST script to create a Weblogic Domain. Script also shows how to configure a Server (Admin Server in this example) and how to deploy an application?

On the successful execution of the script, you will get a Weblogic domain created with specified name at the specified location and with one application already deployed.

WLST Script

# ===== wlsDomainCreationAndConfiguration.py - Crisp Code =======

windows = true;

pathSeparator = '\\';
if not windows:
	pathSeparator = '/';

domainLocation = '';
jvmLocation = '';
domainTemplate = '';

def intialize():
	global domainLocation;
	global jvmLocation;
	global domainTemplate;

	print 'Starting the initialization process';
	# Update the path
	loadProperties("Path/To/PropFile/wlsDomainCreationAndConfiguration.properties");

	domainLocation = domainsDirectory + pathSeparator + domainName;
	print 'Domain Location: ' + domainLocation;

	if len(jvmLocation) == 0:
		jvmLocation = middleWareHome + pathSeparator + 'jrockit_160_24_D1.1.2-4';
	print 'JVM Location: ' + jvmLocation;

	# Using Domain Template - wls.jar
	domainTemplate = middleWareHome + pathSeparator + 'wlserver_10.3' + pathSeparator + 'common' + pathSeparator + 'templates' + pathSeparator + 'domains' + pathSeparator + 'wls.jar';
	print 'Using Domain Template: ' + domainTemplate;

	print 'Initialization completed';

def configureAdminServer():
	print 'Starting Admin Server Configuration...';

	print 'Setting listen address/port...';
	cd('/')
	cd('Server/AdminServer')
	cmo.setListenAddress(listenAddress)
	cmo.setListenPort(int(listenPort))

	print 'SSL Settings...';
	create('AdminServer','SSL')
	cd('SSL/AdminServer')
	set('Enabled', enableSSL)
	set('ListenPort', int(sslListenPort))

	print 'Setting the username/password...';
	cd('/');
	cd('Security/base_domain/User/weblogic');
	cmo.setName(adminUserName);
	cmo.setPassword(adminPassword);
	print 'Admin Server Configuration Completed.';

def setStartupOptions():
	print('Setting StartUp Options...');
	setOption('CreateStartMenu', 'false');
	setOption('ServerStartMode', domainMode);
	setOption('JavaHome', jvmLocation);
	setOption('OverwriteDomain', 'false');

def createCustomDomain():
	print 'Creating the domain...';
	readTemplate(domainTemplate);

	configureAdminServer();
	setStartupOptions();

	writeDomain(domainLocation);
	closeTemplate();
	print 'Domain Created';

def startAndConnnectToAdminServer():
	connUri = 't3://localhost:%s' % listenPort
	print 'Connection URI : ' + connUri;

	print 'Starting the Admin Server...';
	startServer('AdminServer', domainName , connUri, adminUserName, adminPassword, domainLocation,'true',60000,'false');
	print 'Started the Admin Server';

	print 'Connecting to the Admin Server';
	connect(adminUserName, adminPassword, 't3://localhost:%s' % listenPort);
	print 'Connected';

def shutdownAndExit():
	print 'Shutting down the Admin Server...';
	shutdown();
	print 'Exiting...';
	exit();

def deployApplication():
	print 'Starting in edit mode..';
	edit();
	startEdit();

	print 'Deploying the ear..';
	deploy('MyApp01', path=appToDeploy);
	print 'Deployment completed';

	save();
	activate();

# ================================================================
#			Main Code Execution
# ================================================================

intialize();
createCustomDomain();
startAndConnnectToAdminServer();
deployApplication();
shutdownAndExit();
# =========== End Of Script ===============

Code Description
Line #20: load properties from a property file. (Content of the property file is listed in the next section)
Line #39-54: Setting the listening address/port, doing SSL configuration, and setting the user specified user name and password.
Line #57: Function for setting the Weblogic domain start-up options.
Line #66: There are two ways of creating domain – using createDomain or using readTemplate (then writeDomain and closeTemplate) command. If you want to modify the default domain, chose the latter one and that’s what we are doing here.
Line #71: Write the domain configuration information to the specified directory.
Line #72: Close the current domain template.
Line #75: Function for starting and connecting to the AdminServer.
Line #93: Function for deploying an application. If you don’t want to deploy any application, you can remove the call to the function – deployApplication at line #112.

Property File

# WLS Props
middleWareHome=F:\\Oracle\\Middleware

# Domain Props
domainName=ScriptDomain
domainsDirectory=D:\\TestDomains
domainMode=dev
#domainMode=prod

# User Credential Props
adminUserName=weblogic
adminPassword=web10gic

# Admin Server Props
adminServerName=AdminServer
listenAddress=localhost
listenPort=8001
enableSSL=true
sslListenPort=8002

#JVM Props
jvmLocation=

# Custom Props
appName=DemoApp
appToDeploy=Path\\To\\AppToDeploy

Running a WLST Script
Open a command shell and set the WebLogic environment by running the command:
setWLSEnv.cmd (for Windows or ./setWLSEnv.sh for UNIX like systems).

The file setWLSEnv.cmd/setWLSEnv.sh is located in the directory ${WL_HOME}/server/bin. To run a WLST script we can use something like:

java weblogic.WLST path_to_script/wlsDomainCreationAndConfiguration.py

References –
http://docs.oracle.com/cd/E15051_01/wls/docs103/config_scripting/using_WLST.html
http://docs.oracle.com/cd/E13222_01/wls/docs92/config_scripting/domains.html
http://docs.oracle.com/cd/E11035_01/wls100/wlsmbeanref/core/index.html

Advertisements

Comments on: "WLST Script to Create WebLogic Domain" (2)

  1. Hi Chetan,

    Thanks for the blog. Have you seen the following exception in past. /tmp/domain.py is the python file we are using. This works fine in our non-prod but while setting this in production environment, we are getting below exception. I don’t see any out of memory error and unix server configuration in non-prod and prod is same (RHEL 7.2, x86_64) so not sure what else can be wrong. Any lead will be helpful.

    Connecting to t3://10.202.87.229:15000 with userid weblogic …
    No server is running at t3://10.202.87.229:15000, the script will start a new server
    Starting a brand new server at t3://10.202.87.229:15000 with server name svcDomain_admin
    Please see the server log files for startup messages available at /prod/clo/bre_svcDomain
    Starting weblogic server …
    WLST-WLS-1470687421425:
    WLST-WLS-1470687421425:
    WLST-WLS-1470687421425:
    WLST-WLS-1470687421425:
    WLST-WLS-1470687421425:
    ……………………………………………………………………………………Could not connect to the server to verify that it has started. The error returned is: javax.naming.CommunicationException [Root exception is
    java.net.ConnectException: t3://10.202.87.229:15000: Destination unreachable; nested exception is:
    java.net.ConnectException: Connection refused; No available router to destination]
    No stack trace available.
    Done executing the script.
    WLST-WLS-1470687421425: IOException when running WLSTProcess
    WLST-WLS-1470687421425: Stopped draining WLST-WLS-1470687421425
    STDERR: Problem invoking WLST – Traceback (innermost last):
    File “/tmp/domain.py”, line 2182, in ?
    File “/tmp/domain.py”, line 41, in initConfigToScriptRun
    File “”, line 460, in startServer
    File “”, line 646, in raiseWLSTException
    WLSTException: Error occured while performing startServer : Could not start the server, the process might have timed out or there is an Error starting the server. Please refer to the log files for more details.

    java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:255)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
    at java.io.InputStreamReader.read(InputStreamReader.java:167)
    at java.io.BufferedReader.fill(BufferedReader.java:136)
    at java.io.BufferedReader.readLine(BufferedReader.java:299)
    at java.io.BufferedReader.readLine(BufferedReader.java:362)
    at weblogic.management.scripting.utils.WLSTProcess.run(WLSTProcess.java:78)
    at java.lang.Thread.run(Thread.java:662)

  2. Hi, thanks for sharing your code. This is very helpful for me as a newbie in WLST and I have made some modifications in your code. However, I have encountered some issues… By chance are you familiar with this error:

    java -Xms512m -Xmx512m weblogic.WLST /u21/app/oh_app/product/fmw/wlserver_10.3/common/templates/scripts/wlst/custom/CreateDomain.py

    Initializing WebLogic Scripting Tool (WLST) …

    Welcome to WebLogic Server Administration Scripting Shell

    Type help() for help on available commands

    Starting the initialization process
    Domain Location: /u21/app/oh_app/admin/domaintest
    JVM Location: /u21/app/java/jdk
    Using Domain Template: /u21/app/oh_app/product/fmw/wlserver_10.3/common/templates/domains/wls.jar
    Initialization completed
    Creating the domain…
    Starting Admin Server Configuration…
    Setting listen address/port…
    SSL Settings…
    Setting the username/password…
    Admin Server Configuration Completed.
    Setting StartUp Options…
    Domain Created
    Connection URI : t3://localhost:7031
    Starting the Admin Server…
    Starting weblogic server …
    WLST-WLS-1373357779915:
    WLST-WLS-1373357779915:
    WLST-WLS-1373357779915:
    WLST-WLS-1373357779915:
    .WLST-WLS-1373357779915:
    WLST-WLS-1373357779915:
    WLST-WLS-1373357779915:
    ..WLST-WLS-1373357779915:
    ..WLST-WLS-1373357779915:
    WLST-WLS-1373357779915:
    …..WLST-WLS-1373357779915: Exception in thread “Timer-1” java.lang.OutOfMemoryError: PermGen space
    .WLST-WLS-1373357779915: at java.util.WeakHashMap.keySet(WeakHashMap.java:824)
    WLST-WLS-1373357779915: at weblogic.work.RequestManager.purgeHogs(RequestManager.java:922)
    WLST-WLS-1373357779915: at weblogic.work.IncrementAdvisor.run(IncrementAdvisor.java:308)
    WLST-WLS-1373357779915: at java.util.TimerThread.mainLoop(Timer.java:512)
    WLST-WLS-1373357779915: at java.util.TimerThread.run(Timer.java:462)
    ……..WLST-WLS-1373357779915: Exception in thread “DoSManager” java.lang.OutOfMemoryError: PermGen space
    …..Could not connect to the server to verify that it has started. The error returned is: javax.naming.CommunicationException [Root exception is java.net.ConnectException: t3://localhost:7031: Destination unreachable; nested exception is:
    java.net.ConnectException: Connection refused; No available router to destination]
    No stack trace available.
    Problem invoking WLST – Traceback (innermost last):
    File “/u21/app/oh_app/product/fmw/wlserver_10.3/common/templates/scripts/wlst/custom/CreateDomain.py”, line 94, in ?
    File “/u21/app/oh_app/product/fmw/wlserver_10.3/common/templates/scripts/wlst/custom/CreateDomain.py”, line 75, in startAndConnnectToAdminServer
    File “”, line 462, in startServer
    File “”, line 648, in raiseWLSTException
    WLSTException: Error occured while performing startServer : Could not start the server, the process might have timed out or there is an Error starting the server. Please refer to the log files for more details.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: