Few questions that I answered about WLST as a module via various email queries recently.
What is a Jython Module?
In simple words, a jython Module is more or less like a Java class/object that you can import into other Modules. Lets say, you wrote a script/module ‘A.py’ and you defined a function ‘myFunction’. Now you can import this A.py into a different script, say B.py’ and call the function ‘myFunction’. Here’s how you do it.
A.py
——-
def myFunction():
··print “Hello There!”
def printFirstName(myName):
··print “Hello “+myName
B.py
——
import A
A.myFunction()
A.printFirstName(“satya”)
WLST provides a convienient way for you to import it as a module into your scripts and use all the WLST commands that are supported. The advantage of doing this is you can write Jython Modules without any WebLogic dependency and import WLST module into these modules. For example, now you can have another module C.py where you will import wlstModule.py and A.py.
C.py
——
import A
import wlstModule.py as myWLST
# connect to the server
myWLST.connect(‘weblogic’,'weblogic’,'t3://sghattu:7001′)
# call a function from module A
A.printFirstName(“satya”)
#start and edit session and create a server
myWLST.edit()
myWLST.startEdit()
newSvr = myWLST.cmo.createServer(‘ms1′)
newSvr.setListenPort(8001)
myWLST.activate()
myWLST.disconnect()
What is the difference between WLST as a Module and invoking WLST?
If you invoke WLST via ‘java weblogic.WLST‘, WLST instantiates a Jython Interpreter, creates a WLST Namespace and installs all the WLST functions in it. You can import other modules, but you will not have access to WLST functions from these external modules because when you import other modules they will be imported into the Jython’s Default NameSpace not the WLST NameSpace. To use your modules in WLST namespace you will have to execute the module in wlst NameSpace using execfile(externalModule.py).
Where can I find WLST Module and are there any recommendations
WLST Module is under {WL_HOME}/common/wlst/modules/wlstModule.py. You can also generate one using the writeIniFile command.
If you are using WLST as a module, you should use java org.python.util.jython to invoke your scripts. Do not use java weblogic.WLST and import WLST as a module. This will import WLST Module into WLST NameSpace and if you mix the module calls with straight WLST calls, you will see some weird interactions. This is not recommended. Please use straight Jython if you are using WLST as a Module.
_uacct = “UA-2684269-2″;
urchinTracker();