Extending a deployment
We can write ant scripts to extend a project's functionality or perform deployment operations that you would otherwise have to do manually. Scripts can be made to execute automatically before you deploy (or redeploy) a project or after you deploy (or redeploy).
For example, you might write a script to execute before project deployment that adds a servlet to the project's web.xml file to configure a Feature Set, setting properties, or updating servlet definitions and mappings. A script that you write to execute after deployment might execute XMLAccess to create users, groups, pages, or position portlets on a page.
All configuration and project properties are available for inclusion in your script. Project properties reside in the project\.bowstreet file. By default, configuration properties reside in workspace\.metadata\.plugins\com.bowstreet.designer.webapp\deploymentconfigs, where workspace is the directory in which your projects reside. If you have specified a different location in Preferences, the properties reside in the location you specified. Use the property = value syntax in your scripts as illustrated in the example below.
The order in which scripts execute is not guaranteed. Therefore, you should make sure that Feature Sets are configured without dependencies on each other.
You may need to organize your scripts to allow for conditional processing depending on configuration type. For example, if you are deploying to Tomcat, we need to take into account that Tomcat does not have an admin URL.
Predeployment and postdeployment scripts
Put scripts that you want to execute before deployment or redeployment in the project's WEB-INF\bin\predeploy directory. If this directory does not already exist, we need to create it. Put scripts that you want to execute after deployment or redeployment in the project's WEB-INF\bin\postdeploy directory. Again, if this directory does not already exist, we need to create it. Scripts in these directories automatically execute at the appropriate time.
All output is sent to WEB-INF/logs/project>.configuration.log.
Preployment script example
The following is an example of an ant script that calls a utility for adding a servlet definition (SchedulerInit) to the project's web.xml. If you put this script in the project's WEB-INF\bin\predeploy directory, the default target (in this case, "execute") will be called before the application is deployed. We can write your own ant scripts, for example to create your own custom tasks, and put them in the predeploy and postdeploy directories, and they will be executed automatically.
- <project name="addSchedulerServlet" basedir="." default="execute"> - <target name="execute"> <antcall target="addSchedulerServlet" /> </target> - <target name="addSchedulerServlet"> - <ant antfile="${tools.location}/publish/publish_utils.xml" target="addaServlet"> <property name="comment" value="Scheduler servlet for Alerting features." /> <property name="servletName" value="SchedulerInit" /> <property name="displayName" value="SchedulerInit" /> <property name="servletClass" value="com.bowstreet.util.scheduler.init.SchedulerInitializationServlet" /> <property name="loadOnStartup" value="3"> <property name="urlPattern" value="/SchedulerInit" /> <property name="webXmlFile" value="${project.location}/WEB-INF/web.xml: /> </ant> </target> </project>