You need Ant scripts to automate repeated deployment-related tasks. To do so, you need to modify the available example_build.xml file to suit your needs.
More information: ant.apache.org.
The Ant tasks can be executed on a running AS Java. The tasks require a download of the AS Java client libraries. These are delivered with each AS Java installation and reside in folder usr\sap\<SID>\<Instance_Number>\j2ee\j2eeclient. After the libraries are downloaded, they should be made available in the task's class path.
Use the sapimportear task. It takes as a parameter a set of EARs specified by the standard Ant fileset task.
Example
<target name="import_ear"> <sapimportear> <fileset dir="c:/temp"> <include name="**/*.ear"/> </fileset> </sapimportear> </target>
The result is an SAP-compatible deployment archive for each input EAR. Results are located in the <Installation_Directory>/usr/sap/<SID>/<Instance_Number>/j2ee/deployment/SDA folder.
Use the sapdeploy task. It can deploy a set of SDAs located in the fileset directory.
Deployment strategies
The Deploy all option is most suitable when you deploy Java EE archives since they do not have meaningful versions.
Deploy only files with the same or lower versions
Deploy only files with lower versions
Example
<target name="deploy"> <!-- versionrule: "all" | "same_and_lower" | "lower" --> <sapdeploy versionrule="all" throws> . . . </sapdeploy> </target>
throwsError
If set to true, a deployment result status Error will trigger a build exception for the Ant script. Possible values are: yes, true, false, no.
resultProperty
Specifies a name of a property in which value the deployment result status will be stored. The value containing the deployment result status is visible in the target containing the sapdeploy task and in its nested targets.
To specify the error handling mechanism you use the saperrorhandling element. It has the following attributes:
erroraction
errorstrategy
Error Action
Possible values are: prerequisites, deployand undeploy.
Error action prerequisites denotes the preprocess for the deploy or undeploy operation, for example the validity check of the manifest, deployment descriptors and described references for a deployment.
The deploy and undeploy error actions refer to the appropriate operations.
Error Strategies
Stop - The whole deployment process will fail when one of the deployments fails. This is the default and recommended error behavior.
Skip - If the deployment of one of the components fails, all depending components are skipped and not deployed. The process continues with the next component in the deployment queue that does not depend on the failed component. When calculating depending components, deploy time references described in the SAP_MANIFEST are taken into account.
Example
<target name="deploy"> <!-- versionrule: "all" | "same_and_lower" | "lower" --> <sapdeploy versionrule="all"> <!-- erroraction: "prerequisites" | "deploy" | "undeploy" --> <!-- errorstrategy: "stop" | "skip" --> <saperrorhandling erroraction="prerequisites" errorstrategy="stop"/> <saperrorhandling erroraction="deploy" errorstrategy="stop"/> </sapdeploy> </target>
Specify the directory where the archives are.
Example
<target name="deploy"> <!-- versionrule: "all" | "same_and_lower" | "lower" --> <sapdeploy versionrule="all"> <!-- erroraction: "prerequisites" | "deploy" | "undeploy" --> <!-- errorstrategy: "stop" | "skip" --> <saperrorhandling erroraction="prerequisites" errorstrategy="stop"/> <saperrorhandling erroraction="deploy" errorstrategy="stop"/> <!-- specify absolute path to the archives --> <fileset dir="c:/temp"> </fileset> </sapdeploy> </target>
To specify the location of the server on which to deploy you use the sapj2eeengine element. It has the following attributes:
Server host
Server port
User name
User password
Example
<target name="deploy"> <!-- versionrule: "all" | "same_and_lower" | "lower" --> <sapdeploy versionrule="all"> <!-- erroraction: "prerequisites" | "deploy" | "undeploy" --> <!-- errorstrategy: "stop" | "skip" --> <saperrorhandling erroraction="prerequisites" errorstrategy="stop"/> <saperrorhandling erroraction="deploy" errorstrategy="stop"/> <!-- specify absolute path to the archives --> <fileset dir="c:/temp"> </fileset> <sapj2eeengine serverhost="localhost" serverport="50004" username="<user name>" userpassword="<user password>" /> </sapdeploy> </target>
You can undeploy components specified in a list.
If depending stop - If there are components that depend on the software component that has to be undeployed and these are not part of the list of components that have to be undeployed, the undeployment process will stop. The dependent components have to be undeployed for the undeployment to be successful.
Undeploy Depending - All deployed components that depend on the component that has to be undeployed will be undeployed too.
Caution
Please use this strategy with caution. If there is a large dependency chain, you may undeploy applications you did not intend to undeploy.
Example
<target name="undeploy"> <!-- undeploy strategy: "IfDependingStop" | "UndeployDepending" --> <sapundeploy undeploystrategy="IfDependingStop"> . . . </sapundeploy> </target>
You specify them with the saperrorhandling element. It has the following attributes:
erroraction
errorstrategy
Error Action
Use with value undeploy.
Error Strategies
Stop when the first error occurs - The whole undeployment process will fail if one of the undeployments fails. This is the default error behavior.
Skip undeployment of archives depending on the erroneous undeployment - This option is most suitable when undeploying Java EE archives since all your archives will be undeployed. If the undeployment of some of the components fails, all depending components are skipped and not undeployed. The process continues with the next component in the undeployment queue that does not depend on the failed component.
Example
<target name="undeploy"> <!-- undeploy strategy: "IfDependingStop" | "UndeployDepending" --> <sapundeploy undeploystrategy="IfDependingStop"> <!-- erroraction: "prerequisites" | "deploy" | "undeploy" --> <!-- errorstrategy: "stop" | "skip" --> <saperrorhandling erroraction="prerequisites" errorstrategy="stop"/> <saperrorhandling erroraction="undeploy" errorstrategy="stop"/> . . . </sapundeploy> </target>
You have to list the components for undeployment in a plain text file. Components have to be listed as <vendor>/<name> pairs, each on separate line.
Example
isv.com/app1 isv.com/app2
Then the file is referred to as the listfilepath attribute of the sapundeploylist element.
Example
<target name="undeploy"> <!-- undeploy strategy: "IfDependingStop" | "UndeployDepending" --> <sapundeploy undeploystrategy="IfDependingStop"> <!-- erroraction: "prerequisites" | "deploy" | "undeploy" --> <!-- errorstrategy: "stop" | "skip" --> <saperrorhandling erroraction="prerequisites" errorstrategy="stop"/> <saperrorhandling erroraction="undeploy" errorstrategy="stop"/> <!-- specify absolute path to the file containing list with components for undeploy --> <sapundeploylist listfilepath="c:/temp/UndeployList.txt"/> . . . </sapundeploy> </target>
You have to specify the location of the server from which to undeploy. The information you have to enter is the same as the server for deployment.
You should use the task sapparams.
remove = yes | true | on | no | false
This attribute specifies the remove behavior of the operation if it is switched on any parameters contained currently on the engine, which are not in the parameters list for of the operation, will be removed. Hence passing an empty list with enabled remove will clear all parameters from the engine.
The substitution variables should be listed in a plain text file with format: <name>=<value> on each line of the file. If a value is not specified, the variable will not be considered. A warning message is shown. If duplicate parameter names are specified only the first parameter is considered. The second will be skipped. A warning message is shown.
The location of the file is specified as listfilepath attribute of the sapparamslist element.
Example
<target name="params"> <!-- remove: "yes" | "no" --> <sapparams remove="no"> <!-- specify absolute path to the file with params list --> <sapparamslist listfilepath="c:/temp/ParamsList.txt"/> . . . </sapparams> </target>
You have to specify the location of the server from which to undeploy. The information you have to enter is the same as the server for deployment.