The Holy Java

Building the right thing, building it right, fast

Archive for December, 2006

WAS 6.0 ant tasks: Install an app with an external Ant

Posted by Jakub Holý on December 15, 2006

There are special ant taks to install/start/.. an application to a
WebSphere App Server 6.0. It’s easy to run them with WAS’s ant script
(<was>/bin/was_ant.bat) but not so trivial to get them working with an
external ant, which may be necessary because WAS has an old version of ant.
So lets see how to do it.

The important points are:

  • Use IBM JRE
    (or use Sun JRE but setup the environment first by running
    <WAS>/profiles/<your profile>/bin/setupCmdLine in the same
    shell/command line you’ll use to start the ant)
  • Set the environmental variable
    ANT_OPTS=”-Duser.install.root=<WAS>/profiles/<your profile>”
    Strangely, it seems that no other way of passing it to the was ant tasks
    works.
  • Tell Ant where to look for the libraries it needs:
    1. Ant’s own lib/ dir – it must be specified and it must come first
      not to use WAS’ ant
    2. A directory with wsanttasks.jar itself and other jars it depends
      upon (perhaps only wsprofile.jar) – you may specify
      <WAS>/lib
    3. If you want to use scripts in jython, you need to include also
      <WAS>/optionalLibraries

Example:

C:\> set
PATH=C:\development\servers\WebSphere6.0\AppServer\java\jre\bin;%PATH%
C:\> set
JAVA_HOME=C:\development\servers\WebSphere6.0\AppServer\java\jre
C:\> set
ANT_OPTS="-Duser.install.root=C:\development\servers\WebSphere6.0\AppServer/profiles/jh-pokusy"
C:\> c:\apache-ant-1.6.5\bin\ant -verbose -lib ..\apache-ant-1.6.5\lib
-lib c:\development\servers\WebSphere6.0\AppServer\lib -lib
c:\development\servers\WebSphere6.0\AppServer\optionalLibraries -f
myBuild.xml myBuildTarget

myBuild.xml contains:

    <property name="myWas.root"     value="c:\development\servers\WebSphere6.0\AppServer" />

    <taskdef name="wsAdmin"            classname="com.ibm.websphere.ant.tasks.WsAdmin" />
    <taskdef name="wsInstallApp" classname="com.ibm.websphere.ant.tasks.InstallApplication" />
    <taskdef name="wsStartApp" classname="com.ibm.websphere.ant.tasks.StartApplication" />
    <taskdef name="wsUninstallApp" classname="com.ibm.websphere.ant.tasks.UninstallApplication"/>

    <target name="installStartUninstall" depends="_installEarApp,_startEarApp,_uninstallEarApp" />

    <target name="_installEarApp"  description="Deploy the app to WAS 6.0">
                <echo message="Going to deploy '${earToDeploy}' to the server in ${wasroot}..." />
                        <echo message="########## FIRST install ########### ${line.separator}" />
                        <wsInstallApp wasHome="${myWas.root}" conntype="SOAP"
                                      ear="c:\tmp\myApp.ear"
                                      host="localhost" port="8881"
                                      user="me" password="psw"
                                      failonerror="true"
                                      options="-appname MyAppName -verbose true -validateinstall fail -preCompileJSPs true"
                                      />
                        <!-- Note: Anttasks's wsadmin task from was 6.0.0.3 support the attr. profileName="jh-pokusy" -->

                <!-- 1. Ryn my jython script that modifies configuration of the app:
                     (todo: try the atribute: profile="${myWas.root}/bin/setupCmdLine.bat")
                -->
                <wsAdmin wasHome="${myWas.root}" conntype="SOAP" host="localhost" port="8881"
                         host="localhost" port="8881"
                         user="me" password="psw"
                         failonerror="true"
                         script="c:\tmp\configureApplication.jython"
                         lang="jython">
                               <!-- See the script for the arguments it expects -->
                                <arg value="MyAppName"/><!-- app name -->
                </wsAdmin>
        </target>

    <target name="_startEarApp" depends="" description="Start a deployed ear app on the WAS server">
            <wsStartApp wasHome="${myWas.root}" conntype="SOAP"
                        application="MyAppName"
                        host="localhost" port="8881"
                        user="me" password="psw"
                        failonerror="true"
                        />
    </target>

    <target name="_uninstallEarApp" depends="" description="Start a deployed ear app on the WAS server">
            <wsUninstallApp wasHome="${myWas.root}" conntype="SOAP"
                        application="MyAppName"
                        host="localhost" port="8881"
                        user="me" password="psw"
                        failonerror="true"
                        options="-verbose true"
                        />
    </target>

Information

  • host/port for the connection method: see
    <WAS>\profiles\<profile
    name>\properties\wsadmin.properties
  • paths to files (ear, script to execute) – must be absolute!!! – the was
    ant tasks change the working directory => relative paths won’t
    work

Posted in WebSphere | Tagged: , , | 2 Comments »