Use ant for automated deployment and management of applications under WebSphere Application Server 5.x

Source: Internet
Author: User
Tags websphere application server

Note: The tests in this article are based on was5.1. For other was versions, make specific adjustments or refer to the redbooks of the corresponding versions.

WebSphere Application Server (WAS)
It is indeed a very convenient management console for us to easily deploy applications and manage servers, because it cannot copy files as many application servers do.
So it creates some obstacles for the dailybuild process to be fully automated.

In fact, was also provides interfaces (soap and RMI) to manage servers and applications through scripts, but it is a little troublesome to use and has to be studied. You can use the was interface in three ways:

1. wasadmin command line. Most flexible, you can compile your own jacl script file
2. The ant task provided by was encapsulates common functions. ws_ant.bat is available in was_home/bin /.
3. Self-programmed calling.

The following describes ant tasks provided by was to deploy, uninstall, and stop was applications. The ant task we want to use has been encapsulated
The package is was_home/lib/wsanttasks. Jar. Open this file, and in the package com. IBM. websphere. Ant. Tasks
You can see many task classes:

Defaultbindings, installapplication, java2wsdl, jspc, listapplications,
Messages, modulevalidator, nlsecho, servercontrol, serverstatus,
Startapplication, startserver, stopapplication, stopserver,
Uninstallapplication, wsadmin, wsdl2java, wsejbdeploy

Look at the ones that can be explored and used. wsadmin is the leader, which is equivalent to the wsadmin command line. If you are familiar with wsadmin
Command, you can complete all the operations as long as it is used. In the script, wsadmin is used for tasks that are not easy to complete with other tasks. See the ant build. xml below.
Script and the execution Effect of deploying and starting the application.

<Project name = "wasant" basedir = "." default = "installandstart"> <! -- Important: This script requires ant to use was JRE for execution or was_home/bin/ws_ant.bat for execution. Otherwise, you may not be able to execute it successfully, make it run successfully under Sun JRE --> <! -- Modify was_home/properties/wsadmin. com. IBM. WS. scripting. connectiontype = soap # optional rmicom. IBM. WS. scripting. port = 8879 # The port corresponding to the video protocol and settings, which may be 8880com. IBM. WS. scripting. host = 10.128.38.110 # the IP address of the was server to be managed and run was_home/bin/wsadmin. bat is connected to was of 10.128.38.110, But it is strange that was is configured with security, however, if no user name or password is specified, you can use $ adminapp list to display all the above applications. If wsadmin is not configured. properties file, you can directly specify the connection parameters, such as wsadmin-conntype soap-host 10.128.38.110 -Port 8879-user xxxxxxx-Password xxxxwsadmin contains four objects that can be used in the script: $ admincontrol $ adminconfig $ adminapp $ help --> <property name = "was. root "value =" D:/program files/IBM/websphere51/appserver "/> <property name =" wsanttasks. jar "value =" $ {was. root}/lib/wsanttasks. jar "/> <property name =" app. name "value =" test "/> <property name =" ear. file "value =" C:/test. ear "/> <! -- Logon information --> <property name = "username" value = "xxxxxx"/> <property name = "password" value = "xxxxxx"/> <property name = "host" value = "10.128.38.110"/> <property name = "Port" value = "8879"/> <property name = "conntype" value = "Soap"/> <! -- Wsadmin command definition --> <property name = "Startapp. sr3serv1 "value =" $ admincontrol invoke [$ admincontrol querynames type = applicationmanager, process = sr3serv1, *] startapplication $ {app. name} "/> <property name =" Startapp. sr3serv2 "value =" $ admincontrol invoke [$ admincontrol querynames type = applicationmanager, process = sr3serv2, *] startapplication $ {app. name} "/> <property name =" stopapp. sr3serv1 "value =" $ admincontrol Invoke [$ admincontrol querynames type = applicationmanager, process = sr3serv1, *] stopapplication $ {app. name} "/> <property name =" stopapp. sr3serv2 "value =" $ admincontrol invoke [$ admincontrol querynames type = applicationmanager, process = sr3serv2, *] stopapplication $ {app. name} "/> <! -- Start the application server. The server added to the cluster must be started through the node proxy, for example, $ admincontrol invoke [$ admincontrol querynames type = nodeagent, node = sr3, *] launchprocess server1 $ admincontrol invoke [$ admincontrol querynames type = nodeagent, node = sr3, *] launchprocess sr3serv1 is simpler if it is an independent was, start directly $ admincontrol startserver server1 --> <! -- Stop the application server. You can stop the application server regardless of whether it is added to the cluster, for example, the application server under the $ admincontrol stopserver server1 $ admincontrol stopserver sr3serv1 node can be stopped through the node proxy, but server1 cannot use this method $ admincontrol invoke [$ admincontrol querynames type = server, node = sr3, name = sr3serv1, *] Stop {} $ admincontrol invoke [$ admincontrol querynames type = nodeagent, node = sr3, *] launchprocess server1 --> <taskdef name = "wsstartserver" classname = "com. IBM. webSphere. ant. tasks. Startserver "classpath =" $ {wsanttasks. jar} "/> <taskdef name =" wsstopserver "classname =" com. IBM. webSphere. ant. tasks. stopserver "classpath =" $ {wsanttasks. jar} "/> <taskdef name =" wsinstallapp "classname =" com. IBM. webSphere. ant. tasks. installapplication "classpath =" $ {wsanttasks. jar} "/> <taskdef name =" wsuninstallapp "classname =" com. IBM. webSphere. ant. tasks. uninstallapplication "classpath =" $ {wsanttasks. jar }" /> <Taskdef name = "wsstartapp" classname = "com. IBM. webSphere. ant. tasks. startapplication "classpath =" $ {wsanttasks. jar} "/> <taskdef name =" wsstopapp "classname =" com. IBM. webSphere. ant. tasks. stopapplication "classpath =" $ {wsanttasks. jar} "/> <taskdef name =" wslistapps "classname =" com. IBM. webSphere. ant. tasks. listapplications "classpath =" $ {wsanttasks. jar} "/> <taskdef name =" wsadmin "classname =" com. IBM. webSphere. Ant. Tasks. wsadmin "classpath =" $ {wsanttasks. Jar} "/> <! -- Enter llength [$ admincontrol querynames type = application, name = hello_war, *] Number of running instances in the wsadmin command line. If the value is greater than zero, the instance is running, otherwise, it is stopped. --> <! -- Enter $ adminapp list in the wsadmin command line --> <target name = "wslistapps" Description = "list all applications"> <wslistapps conntype = "Soap" host = "10.128.38.110" port = "8879" user = "xxxxxx" Password = "xxxxxx" washome = "$ {was. root} "> </wslistapps> </Target> <! -- Enter $ adminapp install C:/test. ear {-cluster sr3cluster-appname test-usedefaultbindings} $ adminconfig save # Do not forget to save it. Otherwise, you can run $ adminapp options C:/test. ear to check what options can be specified to install this package --> <target name = "wsinstallapp" Description = "install application $ {app. name} "> <wsinstallapp user =" $ {username} "Password =" $ {password} "host =" $ {Host} "ear =" $ {ear. file} "Port =" $ {port} "conntype =" $ {conntype} "W Ashome = "$ {was. Root}" Options = "-cluster sr3cluster-appname $ {app. name}-usedefaultbindings"> </wsinstallapp> </Target> <! -- It is relatively simple to uninstall an application, as long as $ adminapp uninstall test $ adminconfig save --> <target name = "wsuninstallapp" Description = "Uninstall application $ {app. name} "> <wsuninstallapp user =" $ {username} "Password =" $ {password} "host =" $ {Host} "conntype =" $ {conntype} "Port = "$ {port}" washome = "$ {was. root} "application =" $ {app. name} "> </wsuninstallapp> </Target> <! -- Start the application. According to the Redbook, $ admincontrol invoke [$ admincontrol querynames type = applicationmanager, node = sr3, *] startapplication test cannot start the application, the error "unable to create objectname" appears. You must start $ admincontrol invoke [$ admincontrol querynames type = applicationmanager, process = server1 on all servers one by one, *] startapplication test $ admincontrol invoke [$ admincontrol querynames type = applicationmanager, process = sr3serv1, *] startapplication test $ Admin Control invoke [$ admincontrol querynames type = applicationmanager, process = sr3serv2, *] startapplication test --> <! -- Because the following script uses $ admincontrol invoke [$ admincontrol querynames type = applicationmanager, node = sr3, *] startapplication test, the same error is reported, "objectname cannot be created" error. Use wsadmin to directly execute the command to start <target name = "wsstartapp" Description = "Start application $ {app. name} "> <wsstartapp user =" $ {username} "Password =" $ {password} "host =" $ {Host} "conntype =" $ {conntype} "Port = "$ {port}" washome = "$ {was. root} "application =" $ {app. name} "> </wsst Artapp> </Target> --> <! -- Use wsadmin to directly execute the command to start the application --> <target name = "wsstartapp" Description = "Start application $ {app. name} "> <echo> Start application $ {app. name} on sr3serv1/sr3serv2 </echo> <wsadmin user = "$ {username}" Password = "$ {password}" host = "$ {Host}" conntype = "$ {conntype} "Port =" $ {port} "washome =" $ {was. root} "command =" $ {Startapp. sr3serv1 };$ {Startapp. sr3serv2} "> </wsadmin> </Target> <! -- Start the application. According to the Redbook, $ admincontrol invoke [$ admincontrol querynames type = applicationmanager, node = sr3, *] startapplication test cannot start the application, the error "unable to create objectname" appears. You must start $ admincontrol invoke [$ admincontrol querynames type = applicationmanager, process = server1 on all servers one by one, *] stopapplication test $ admincontrol invoke [$ admincontrol querynames type = applicationmanager, process = sr3serv1, *] stopapplication test $ adminco Ntrol invoke [$ admincontrol querynames type = applicationmanager, process = sr3serv2, *] stopapplication test --> <! -- Because the following script uses $ admincontrol invoke [$ admincontrol querynames type = applicationmanager, node = sr3, *] startapplication test, the same error is reported, "objectname cannot be created" error. Use wsadmin to directly execute the command to start <target name = "wsstopapp" Description = "Stop Application $ {app. name} "> <wsstopapp user =" $ {username} "Password =" $ {password} "host =" $ {Host} "conntype =" $ {conntype} "Port = "$ {port}" washome = "$ {was. root} "application =" $ {app. name} "> </WSS Topapp> </Target> --> <! -- Use wsadmin to directly execute the command to start the application --> <target name = "wsstopapp" Description = "Start application $ {app. name} "> <echo> Stop Application $ {app. name} on sr3serv1/sr3serv2 </echo> <wsadmin user = "$ {username}" Password = "$ {password}" host = "$ {Host}" conntype = "$ {conntype} "Port =" $ {port} "washome =" $ {was. root} "command =" $ {stopapp. sr3serv1 };$ {stopapp. sr3serv2} "> </wsadmin> </Target> <! -- Actual task combination --> <target name = "installandstart" Description = "Install and start $ {app. name} "> <antcall target =" wsinstallapp "/> <antcall target =" wsstartapp "/> </Target> <target name =" stopanduninstall "Description =" Stop and uninstall $ {app. name} "> <antcall target =" wsstopapp "/> <antcall target =" wsuninstallapp "/> </Target> </Project>

Execution result:

Buildfile:
E:/workspace/Eclipse/testswt/build. xml

Installandstart

:

Wsinstallapp

:

[
Wsinstallapp
] Installing the application

[/C]... </span> <span style = "color: #000080;"> wsadmin </span> <span style = "color: # 0000ff;">] wasx7209i: use the soap connector to connect to the "dmgr" process on the node sr3manager. The process type is deploymentmanager [</span> <span style = "color: #000080; "> wsadmin </span> <span style =" color: # 0000ff; ">] adma5016i: Start and install test. </Span> <span style = "color: #000080;"> wsadmin </span> <span style = "color: # 0000ff;">] adma5005i: configure the application test [</span> <span style = "color: #000080;"> wsadmin </span> <span style = "color: # 0000ff; ">] adma5001i: The application binary file is stored in/opt/websphere51/deploymentmanager/wstemp/script1_f1164d5a/workspace/cells/sr3network/applications/test. ear/test. ear [wsadmin] adma5011i: The application test temporary directory is cleared. </Span> <span style = "color: # 0000ff;"> [</span> <span style = "color: #000080; "> wsadmin </span> <span style =" color: # 0000ff; ">] adma5013i: The application test is successfully installed. [</Span> <span style = "color: #000080;"> <u> wsinstallapp </u> </span> <span style = "color: # 0000ff; ">] installed Application 1

Wsstartapp

:
[
Echo

] Start application test on sr3serv1/sr3serv2

[
Wsadmin

] Wasx7209i: Use the soap connector to connect to the process "dmgr" on the node sr3manager. The process type is deploymentmanager.
Build successful
Total time: 33 seconds

Note:

1. There are a lot of comments between build. XML to make it clearer, and it is also used to compare and understand with the wsadmin command, which can be removed in reality.

2. the above tests are based on clusters. Under sr3cluster, there are two application servers: sr3serv1 and
Sr3serv2, where the application is deployed on sr3cluster. For was with clusters not configured
It will be simpler. It is also mentioned in the script. Please check your discretion and crop it. If you have any questions, please discuss it with me.
Change-cluster sr3cluster to-server server1 in options of wsinstallapp, and change process = server1 in the command when the application starts and stops.

3. Was security is configured. Therefore, the user name and password must be provided during logon.

4. In this example, an ear package is deployed. For example, if a war package is deployed, you must specify the context for accessing the web in options, such as-contextroot test.

5. the application is started immediately after the application is installed. It may fail to be started because the server has not actually completed the configuration of the new application, therefore, you can <sleep seconds = "5"/> wait a few seconds after installing the application.

Related information:

1. Deploy the ear on the command line in was

2. Use wsadmin)

3. wsadmin manages WebSphere

4. IBM WebSphere Application Server 5.0 system management and configuration Redbook
5. Overview of unattended deployment of Websphere Application server6.0

This article link http://unmi.cc/ant-auto-deploy-application-was-5-x
, From yeye huangying unmi blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.