ws_ant examples

This page contains example usage of WebSphere Application Server Ant tasks and the ws_ant Qshell script.

Example buildfile

This buildfile contains example tasks and targets for the Ant tasks supplied by WebSphere Application Server.

<project name="wsant test" default="main" basedir="."> 

  <taskdef name="wsStartServer" classname="com.ibm.websphere.ant.tasks.StartServer"/>
  <target name="startServer">
    <wsStartServer server="server1"/>
  </target>
  
  <taskdef name="wsStopServer" classname="com.ibm.websphere.ant.tasks.StopServer"/>
  <target name="stopServer">
    <wsStopServer server="server1"/>
  </target>
  
  <taskdef name="wsStatus" classname="com.ibm.websphere.ant.tasks.ServerStatus"/>
  <target name="status">
    <wsStatus server="server1"/>
  </target>
  
  <taskdef name="wsAdmin" classname="com.ibm.websphere.ant.tasks.WsAdmin"/>
  <target name="admin">
    <wsAdmin command="$$AdminApp list"/>
  </target>
  
  <taskdef name="wsListApps" 
    classname="com.ibm.websphere.ant.tasks.ListApplications"/>
  <target name="listApps">
    <wsListApps/>
  </target>

  <taskdef name="wsStopApp" classname="com.ibm.websphere.ant.tasks.StopApplication"/>
  <target name="stopApp">
    <wsStopApp application="DefaultApplication"/>
  </target>
  
  <taskdef name="wsStartApp"
    classname="com.ibm.websphere.ant.tasks.StartApplication"/>
  <target name="startApp">
    <wsStartApp application="DefaultApplication"/>
  </target>
  
  <taskdef name="wsUninstallApp"
    classname="com.ibm.websphere.ant.tasks.UninstallApplication"/>
  <target name="uninstall">
    <wsUninstallApp application="DefaultApplication"/>
  </target>

  <taskdef name="wsInstallApp"
    classname="com.ibm.websphere.ant.tasks.InstallApplication"/>
  <target name="install">
    <wsInstallApp 
      ear="${was.install.root}/installableApps/DefaultApplication.ear"
      options="-appname DefaultApplication -usedefaultbindings"/>
  </target>

  <taskdef name="wsDftBind" 
    classname="com.ibm.websphere.ant.tasks.DefaultBindings"/>
  <target name="bind">
    <wsDftBind
      ear="${was.install.root}/installableApps/DefaultApplication.ear"
      outputFile="${user.install.root}/installableApps/DefaultApplication.ear"/>
  </target>
  
  <taskdef name="wsJspC" classname="com.ibm.websphere.ant.tasks.JspC"/>
  <target name="jspc">
    <wsJspC
      src="${user.install.root}/installedApps/${was.node.name}/
        DefaultApplication.ear/DefaultWebApplication.war"
      toDir="${user.install.root}/installableApps/compiledJSPs"/>
  </target>
  
  <taskdef name="wsEjbDeploy"
    classname="com.ibm.websphere.ant.tasks.WsEjbDeploy"/>
  <target name="ejbdeploy">
    <wsEjbDeploy
      inputJar="${was.install.root}/samples/lib/TechnologySamples/
        BasicCalculatorEJB.jar"
      outputJar="${user.install.root}/installableApps/
        deployedBasicCalculatorEJB.jar"/>
  </target>

  <taskdef name="wsValidateModule"
    classname="com.ibm.websphere.ant.tasks.ModuleValidator"/>
  <target name="validate">
    <wsValidateModule
      src="${was.install.root}/installableApps/DefaultApplication.ear"/>
  </target>

  <taskdef name="wsNLSEcho" classname="com.ibm.websphere.ant.tasks.NLSEcho"/>
  <target name="nlsmsg">
    <wsNLSEcho key="ISUCCESS" bundle="installapps"
      message="Installing app {0} successful on {1}" replace="hello;;server1"/>
  </target>
  
</project>

Example commands

The following examples show commands run from Qshell and the resulting output. The buildfile shown above was used for these examples.

List installed applications

Enter this command at the Qshell prompt:

 > /QIBM/ProdData/WebAS5/Base/bin/ws_ant listApps -buildfile /home/ant/tasks.xml
  -instance default

The output of the command is:

   Buildfile: /home/ant/tasks.xml

   listApps:
     [wsadmin] WASX7209I: Connected to process "server1" on node MyiSeries
      using SOAP connector;  The type of process is: UnManagedProcess
     [wsadmin] "DefaultApplication", "adminconsole", "ivtApp"
     [wsadmin] Java Result: 59

   BUILD SUCCESSFUL

   Total time: 34 seconds
   $

Display server status

Enter this command at the Qshell prompt:

 > /QIBM/ProdData/WebAS5/Base/bin/ws_ant status -buildfile /home/ant/tasks.xml
  -instance default

The output of the command is:

   Buildfile: /home/ant/tasks.xml

   status:
   [serverStatus] ADMU0116I: Tool information is being logged in file
   [serverStatus] /QIBM/UserData/WebAS5/Base/default/logs/server1/serverStatus.log
   [serverStatus] ADMU0500I: Retrieving server status for server1
   [serverStatus] ADMU0508I: The Application Server "server1" is STARTED

   BUILD SUCCESSFUL

   Total time: 59 seconds
   $

Install an application

Enter this command at the Qshell prompt:

 > /QIBM/ProdData/WebAS5/Base/bin/ws_ant install -buildfile /home/ant/tasks.xml
  -instance default

The output of the command is:

   Buildfile: /home/ant/tasks.xml

   install:
   [wsInstallApp] Installing Application [/QIBM/ProdData/WebAS5/Base/installableApps
     /DefaultApplication.ear]...
     [wsadmin] WASX7209I: Connected to process "server1" on node MyiSeries using SOAP
       connector;  The type of process is: UnManagedProcess
     [wsadmin] WASX7327I: Contents of was.policy file:
     [wsadmin]  // WebSphere Application Server Security Policy for the Default
       Application
     [wsadmin]
     [wsadmin] // Required for Snoop Servlet's call to get User Name from
       getUserPrincipal()
     [wsadmin] grant codeBase "file:DefaultWebApplication.war" {
     [wsadmin]   permission java.security.SecurityPermission "printIdentity";
     [wsadmin] };
     [wsadmin]
     [wsadmin]
     [wsadmin] ADMA5016I: Installation of DefaultApplication started.
     [wsadmin] ADMA5005I: Application DefaultApplication configured in WebSphere
       repository
     [wsadmin] ADMA5001I: Application binaries saved in
       /QIBM/UserData/WebAS5/Base/default/wstemp/Scriptf0c0c50b77/workspace/cells
       /MyiSeries/applications/DefaultApplication.ear/DefaultApplication.ear
     [wsadmin] ADMA5011I: Cleanup of temp dir for app DefaultApplication done.
     [wsadmin] ADMA5013I: Application DefaultApplication installed successfully.
     [wsadmin] Java Result: 59
   [wsInstallApp] Installed Application [/QIBM/ProdData/WebAS5/Base/installableApps
     /DefaultApplication.ear]

   BUILD SUCCESSFUL

   Total time: 1 minute 12 seconds
   $