Date Created: Fri 26-Aug-2011



    Creating an IBM WebSphere Application Server profile using ANT and manageProfiles command

    Using the following help command for the WAS command file called manageProfiles, we can determine what command options(Switches) are available for use by ANT.


    <WAS_INSTALL_ROOT>/\bin>manageprofiles.bat -create -help

    Function:
    Creates a new profile

    Syntax:
    manageprofiles -create -<argument> <argument parameter> ...

    Arguments:

    The following command line arguments are required for this mode:

    -templatePath <argument parameter>: The fully qualified path name of the profile template tha
    file system.
    -profileName <argument parameter>: The name of the profile.
    -profilePath <argument parameter>: The intended location of the profile in the file system.

    The following command line arguments are optional, and have no default values:

    -isDefault <argument parameter>: Make this profile the default target of commands that do not
    arameter.
    -omitAction <argument parameter>: Omit optional features.

    Note: Command-line arguments are case sensitive.
    Note: If argument accepts a parameter containing spaces, the parameter must be enclosed in "double
    Note: The default profile template is "default" and may be overridden by the -templatePath switch.
    Note: Each profile template will have its own set of required and optional arguments.

    ============

    There are a few command missing which we wil add to our ANT script, namely how to specify the Global Security adminUsername and adminPassword for when you want to create a secure profile.

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="Log View EAR build script" default="buildAll" basedir=".">
    <echo message="*** BEGIN initial properties ***" />
    <property name="HOSTNAME" value="localhost" />
    <echo message="HOSTNAME = ${HOSTNAME}" />
    <property name="WAS_HOME" value="c:/Program Files (x86)/ibm/WebSphere/AppServer" />
    <echo message="WAS_HOME = ${WAS_HOME}" />
    <property name="WAS_PROFILE_ROOT" value="c:/Program Files (x86)/ibm/WebSphere/AppServer/profiles" />
    <echo message="WAS_PROFILE_ROOT = ${WAS_PROFILE_ROOT}" />
    <property name="ADMIN_USERNAME" value="wasadmin" />
    <echo message="ADMIN_USERNAME = ${ADMIN_USERNAME}" />
    <property name="ADMIN_PASSWORD" value="wasadmin" />
    <echo message="ADMIN_PASSWORD = ${ADMIN_PASSWORD}" />
    <echo message="user.name = ${user.name}" />
    <property name="SERVER_NAME" value="server1" />

    <echo message="*** END initial properties ***" />


    <taskdef resource="net/sf/antcontrib/antlib.xml" classpath="D:/ant-contrib/ant-contrib-1.0b3.jar" onerror="ignore" />

    <!--
    <property name="WAS_STARTING_PORT" value="10000" />
    -->


    <if>
    <not>
    <isset property="WAS_HOME" />
    </not>
    <then>
    <input message="Please enter WAS installtion root (default=${WAS_HOME}): " addproperty="WAS_HOME" defaultvalue="${WAS_HOME}" />
    </then>
    </if>
    <echo message="WAS_HOME=${WAS_HOME}" />

    <if>
    <not>
    <isset property="WAS_PROFILE_ROOT" />
    </not>
    <then>
    <input message="Please enter WAS profile root path (default=${WAS_PROFILE_ROOT}): " addproperty="WAS_PROFILE_ROOT" defaultvalue="${WAS_PROFILE_ROOT}" />
    </then>
    </if>
    <echo message="WAS_PROFILE_ROOT=${WAS_PROFILE_ROOT}" />

    <if>
    <not>
    <isset property="WAS_PROFILE_NAME" />
    </not>
    <then>
    <input message="Please enter WAS profile name (default=${WAS_PROFILE_NAME}): " addproperty="WAS_PROFILE_NAME" defaultvalue="${WAS_PROFILE_NAME}" />
    </then>
    </if>
    <echo message="WAS_PROFILE_NAME=${WAS_PROFILE_NAME}" />


    <if>
    <isset property="WAS_STARTING_PORT" />
    <then>
    <echo message="Setting WAS_STARTING_PORT to value of ${WAS_STARTING_PORT}" />
    <property name="WAS_STARTING_PORT" value="${WAS_STARTING_PORT}" />
    </then>
    <else>
    <input message="Please enter Websphere port (default=10000): " addproperty="WAS_STARTING_PORT" defaultvalue="10000" />
    </else>
    </if>
    <echo message="WAS_STARTING_PORT=${WAS_STARTING_PORT}" />


    <condition property="WASManageProfilesScript" value="${WAS_HOME}/bin/manageprofiles.bat">
    <and>
    <os family="windows" />
    </and>
    </condition>

    <condition property="WASManageProfilesScript" value="${WAS_HOME}/bin/manageprofiles.sh">
    <and>
    <os family="unix" />
    </and>
    </condition>

    <echo message="WASManageProfilesScript=${WASManageProfilesScript}" />

    <target name="createProfile" depends="deleteProfile">
    <exec executable="${WASManageProfilesScript}">
    <arg value="-create" />
    <arg value="-winserviceCheck" />
    <arg value="false" />
    <arg value="-omitAction" />
    <arg value="samplesInstallAndConfig" />
    <arg value="-templatePath" />
    <arg value="${WAS_HOME}/profileTemplates/default" />
    <arg value="-profilePath" />
    <arg value="${WAS_PROFILE_ROOT}/${WAS_PROFILE_NAME}" />
    <arg value="-nodeName" />
    <arg value="${WAS_PROFILE_NAME}-${HOSTNAME}-Node" />
    <arg value="-cellName" />
    <arg value="${WAS_PROFILE_NAME}-${HOSTNAME}-Cell" />
    <arg value="-enableAdminSecurity" />
    <arg value="true" />
    <arg value="-adminUserName" />
    <arg value="${ADMIN_USERNAME}" />
    <arg value="-adminPassword" />
    <arg value="${ADMIN_PASSWORD}" />
    <arg value="-profileName" />
    <arg value="${WAS_PROFILE_NAME}" />
    <arg value="-hostName" />
    <arg value="${HOSTNAME}" />
    <arg value="-isDeveloperServer" />
    <arg value="-startingPort" />
    <arg value="${WAS_STARTING_PORT}" />
    </exec>
    <echo message="Profile creation complete." />
    </target>

    <target name="deleteProfile" depends="">
    <echo message="Deleting profile.." />
    <input message="Profile folder={$WAS_PROFILE_ROOT} already exists. Do you want to delete this profile first ?" validargs="Yes,No" addproperty="WAS_PROFILE_CONFIRM_DELETE" defaultvalue="Yes" />
    <if>
    <equals arg1="${WAS_PROFILE_CONFIRM_DELETE}" arg2="Yes" />
    <then>
    <!-- can't delete if the server is running, so make sure it's down -->
    <antcall target="stopServer" inheritall="true" inheritrefs="true" />
    <echo message="Deleting profile ${WAS_PROFILE_NAME}. Please wait....." />

    <exec executable="${WASManageProfilesScript}">
    <arg value="-delete" />
    <arg value="-profileName" />
    <arg value="${WAS_PROFILE_NAME}" />
    </exec>

    <delete dir="${WAS_PROFILE_ROOT}/${WAS_PROFILE_NAME}" failonerror="false" />
    <echo message="Profile deleted" />
    </then>
    <else>
    <fail message="Profile folder [${WAS_PROFILE_ROOT}] still exists. Please delete the ${WAS_PROFILE_NAME} folder first." />
    </else>
    </if>


    </target>


    <target name="buildAll" depends="deleteProfile, createProfile">

    </target>

    <target name="stopServer">
    <condition property="stopServerScript" value="${WAS_HOME}/bin/stopServer.sh">
    <and>
    <os family="unix" />
    </and>
    </condition>
    <condition property="stopServerScript" value="${WAS_HOME}/bin/stopServer.bat">
    <and>
    <os family="windows" />
    </and>
    </condition>
    <if>
    <available file="${stopServerScript}" />
    <then>
    <exec executable="${stopServerScript}">
    <arg value="${SERVER_NAME}" />
    </exec>
    </then>
    <else>
    <echo message="Could not stop server - couldn't find ${stopServerScript}." />
    </else>
    </if>
    </target>
    </project>


Middleware Mentor - Steven Charles Robinson

About Me

Steve Robinson has been working in IT for over 15 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware consulting. Steve comes from both an administration and development background.

Before moving to JEE, Steve was an accomplished developer and consultant for both IBM Lotus Notes and Microsoft .NET Technologies.

Follow Steve as @stevencrobinson on twitter.

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Oracle WebLogic Categories

JBoss Categories

Other Categories