wlshell can be used in conjuction with Ant to automate WebLogic configuration and monitoring tasks.
The following example illustrates how to integrate wlshell into Ant build scripts. The Ant build script uses a Java task to call the main class of wlshell, passing the name of a script file for execution and some variables to customize the execution of the script.
This particular example connects to a server and creates a JMSServer with a JMSQueue. The server, credentials and resource names are passed to wlshell as arguments. Some of those values could also be supplied using the Run Command file (.wlshrc) located in the directory where wlshell is started.
Ant build script:
<project name="wlshellProject" default="createJMS" basedir=".">
<description>
create a JMSServer with a Queue using wlshell
</description>
<property name="basedir" location="."/>
<property name="weblogicdir" location="c:/bea812/weblogic81"/>
<property name="wlshelldir" location="d:/local/java/wlshell-2.0.0"/>
<property name="server" value="localhost:7001"/>
<property name="user" value="weblogic"/>
<property name="password" value="weblogic"/>
<property name="queue" value="rec.queue"/>
<property name="jmsServer" value="msgServer"/>
<path id="project.class.path">
<pathelement path="${weblogicdir}/server/lib/weblogic.jar"/>
<pathelement path="${wlshelldir}/lib/wlshell-2.0.1.jar"/>
<pathelement path="${wlshelldir}/lib/log4j-1.2.8.jar"/>
</path>
<target name="createJMS">
<java classname="wlshell.Main" fork="yes" dir="${basedir}">
<arg line="-f ${basedir}/jms.wlsh -v server=${server} -v user=${user} -v password=${password} -v jmsServer=${jmsServer} -v queue=${queue}"/>
<classpath>
<path refid="project.class.path"/>
</classpath>
</java>
</target>
</project>
wlshell script:
#connect to the server
connect
#create JMSServer and Queue
mkdir /JMSServer/$jmsServer
mkdir /JMSQueue/$queue
cd $LAST
set JNDIName expr("jms" + $queue)
set Parent /JMSServer/$jmsServer
#save domain configuration
invoke weblogic:/Repository/Default/saveDomain $DOMAIN
#disconnect from the server
disconnect
#exit wlshell
exit
Output:
C:\local\ant>ant
Buildfile: build.xml
createJMS:
[java] wlshell, a shell for BEA WebLogic Server. Version 2.0.0
[java] by Paco Gomez (c) 2002 - 2004. www.wlshell.com
[java] type "help" for a list of commands
[java] wlsh [not connected]> connect
[java] connecting to t3://localhost:7001 as weblogic...done
[java] connection information:
[java] - the server name is "myserver" and belongs to "sandbox" domain
[java] - this server is running as the administration server
[java] - the shell is accessing all MBeans in this domain
[java] - the server version is:
[java] WebLogic Server 8.1 SP2 Fri Dec 5 15:01:51 PST 2003 316284
[java] WebLogic XMLX Module 8.1 SP2 Fri Dec 5 15:01:51 PST 2003 316284
[java] - see /ServerRuntime/myserver for more runtime information.
[java] connected to myserver*
[java] Searching for MBeans in myserver...done
[java] - Domains: [JMImplementation, Security, WeblogicManagement, sandbox, weblogic]
[java] - Types: 90
[java] - MBeans: 685
[java] accessing jndi@myserver...done
[java]
[java] wlsh sandbox:/> mkdir /JMSServer/$jmsServer
[java] creating sandbox:/JMSServer/msgServer ...done
[java] sandbox:/JMSServer/msgServer
[java] wlsh sandbox:/> mkdir /JMSQueue/$queue
[java] creating sandbox:/JMSQueue/rec.queue ...done
[java] sandbox:/JMSQueue/rec.queue
[java] wlsh sandbox:/> cd $LAST
[java] sandbox:/JMSQueue/rec.queue
[java] wlsh sandbox:/JMSQueue/rec.queue> set JNDIName expr("jms" + $queue)
[java] sandbox:/JMSQueue/rec.queue/JNDIName
[java] old value: null (null)
[java] new value: jmsrec.queue (java.lang.String)
[java] wlsh sandbox:/JMSQueue/rec.queue> set Parent /JMSServer/$jmsServer
[java] sandbox:/JMSQueue/rec.queue/Parent
[java] old value: sandbox:Name=sandbox,Type=Domain (weblogic.management.WebLogicObjectName)
[java] new value: [Caching Stub]Proxy for sandbox:Name=msgServer,Type=JMSServer (weblogic.management.configuration.JMSServerMBean_Stub)
[java] wlsh sandbox:/JMSQueue/rec.queue> invoke weblogic:/Repository/Default/saveDomain $DOMAIN
[java] (this operation doesn't return any value) null
[java] wlsh sandbox:/JMSQueue/rec.queue> disconnect
[java] disconnected
[java] wlsh [not connected]> exit
[java] bye!
BUILD SUCCESSFUL
Total time: 6 seconds