Monthly Archives: April 2009

Jython script to create domain and set database connection using WLST.

In one of my recent project I have to prepare a jython script to create a domain and database connection and up this database connection on admin server in Weblogic environment. I have gone through various Weblogic documentation and few other websites where I find some examples but no explanation was given about these example. Being a new jython user I found it very difficult to make changes in the code according to my requirement. Here I am trying to explain those things along with script, so that whenever somebody have to modifiy the script, he/she can do it with ease according to his/her requirement.


Here is the script.

(When you copy this script, please remove all lines which are in brackets in italic fonts and in the color you are reading now. These are explanation lines.)



# Open a domain template.





(Here you can modify the template by extract wls.jar file on your local disk. Put all the changes which are specific to your project. You can put all library jar’s in modified domain which your application need and you want to deliver to client. Other changes like which JDK you want to use SUN or JRocket you can define here. Also you can set  JAVA_Opetions for your environment. Then again make a jar file with these changes with some other name like myProject.jar to use new template. When your script will use this customized template, it will set your environment on any machine. All you have to do is to deliver this customized template (myProject.jar) and your script ( will explain every thing about template customization in my next post on this blog.)


#============================================================# #Configure the Administration Server and SSL port.

# To enable access by both local and remote processes, you should not set the

# listen address for the server instance (that is, it should be left blank or not set).

# In this case, the server instance will determine the address of the machine and

# listen on it.




set(‘ListenPort’, 7001)

(Leave above section as it is if you want your application to run on 7001. Or you can change port number according to your requirement.)




set(‘Enabled’, ‘True’)

set(‘ListenPort’, 7002)


(Leave above section as it is.)



# Define the user password for weblogic.










(In the above section, you have to change the following variables 1. DOMAIN_NAME = replace this with the name of domain. 2. YOUR_USERNAME = replace this with the name you want to use for login in WL console 3. YOUR_PASSWORD = replace this with the password you want to set for login in WL console. Left rest of the things as it is.) 



# Create and configure a JDBC Data Source, and sets the JDBC user.




create(‘YOUR_DATABASE_NAME’, ‘JDBCSystemResource’)






set(‘PasswordEncrypted’, ‘YOUR_DATABASE_PASSWORD’)

set(‘UseXADataSourceInterface’, ‘false’)



create(‘YOUR_DATABASE_USER_NAME’, ‘Property’)







set(‘JNDIName’, java.lang.String(“jdbc/YOUR_DATABASE_NAME”))





set(‘TestTableName’,’SQL SELECT 1 FROM iitables’)


(In the above section, you have to change the following variables

1. YOUR_DATABASE_NAME = replace this with the name of your database.

2. YOUR_DATABASE_USER_NAME = replace this with the user name with which you access data base.

3. YOUR_DATABASE_PASSWORD = replace this with the password you want to set for login in WL console.

4) ca.ingres.jdbc.IngresDriver = replace this driver with the name of driver of database which you want to use.

5) jdbc:ingres://localhost:21071/YOUR_DATABASE_NAME  = replace this with the URL of your database.

The best way to get this URL and driver name is by first creating a dataresource manually from WL console and copy these fields from there. Left rest of the things as it is.)



# Target resources to the servers.




assign(‘JDBCSystemResource’, ‘YOUR_DATABASE_NAME’, ‘Target’, ‘AdminServer’)


(In the above section, you have to change the following variables

1. YOUR_DATABASE_NAME = replace this with the name of your database. Left rest of the things as it is.)



# Write the domain and close the domain template.



setOption(‘OverwriteDomain’, ‘true’)




(In the above section, you just have to give the path of domain where you want to create it. We are just assuming that your WL is installed at C:/ drive. Left rest of the things as it is.)



# Exit WLST.






If you have any further question or you need some more clarification on this script, you can write me back. Below are the links which help me in my course of action. You can refer to these links as they might prove handy in your requirement.


Any suggestion or comment on this post is most welcome.






Filed under WebLogic