Example of a build.xml for an EAR that deploys in WebSphere 6
Asked Answered
T

4

22

I'm trying to convince my providers to use ANT instead of Rational Application Development so anyone can recompile, recheck, redeploy the solution anyplace, anytime, anyhow. :P

I started a build.xml for a project that generates a JAR file but stopped there and I need real examples to compare notes. My good friends! I don't have anyone close to chat about this!

This is my build.xml so far.

(*) I edited my question based in the suggestion of to use pastebin.ca

Tatianna answered 6/8, 2008 at 21:55 Comment(0)
B
14

My Environment: Fedora 8; WAS 6.1 (as installed with Rational Application Developer 7)

The documentation is very poor in this area and there is a dearth of practical examples.

Using the WebSphere Application Server (WAS) Ant tasks

To run as described here, you need to run them from your server profile bin directory using the ws_ant.sh or ws_ant.bat commands.

<?xml version="1.0"?>
<project name="project" default="wasListApps" basedir=".">
    <description>
        Script for listing installed apps.
        Example run from:
        /opt/IBM/SDP70/runtimes/base_v61/profiles/AppSrv01/bin
    </description>

    <property name="was_home"
        value="/opt/IBM/SDP70/runtimes/base_v61/">
    </property>
    <path id="was.runtime">
        <fileset dir="${was_home}/lib">
            <include name="**/*.jar" />
        </fileset>
        <fileset dir="${was_home}/plugins">
            <include name="**/*.jar" />
        </fileset>
    </path>
    <property name="was_cp" value="${toString:was.runtime}"></property>
    <property environment="env"></property>

    <target name="wasListApps">
        <taskdef name="wsListApp"
            classname="com.ibm.websphere.ant.tasks.ListApplications"
            classpath="${was_cp}">
        </taskdef>
        <wsListApp wasHome="${was_home}" />
    </target>

</project>

Command:

./ws_ant.sh -buildfile ~/IBM/rationalsdp7.0/workspace/mywebappDeploy/applist.xml

A Deployment Script

<?xml version="1.0"?>
<project name="project" default="default" basedir=".">
<description>
Build/Deploy an EAR to WebSphere Application Server 6.1
</description>

    <property name="was_home" value="/opt/IBM/SDP70/runtimes/base_v61/" />
    <path id="was.runtime">
        <fileset dir="${was_home}/lib">
            <include name="**/*.jar" />
        </fileset>
        <fileset dir="${was_home}/plugins">
            <include name="**/*.jar" />
        </fileset>
    </path>
    <property name="was_cp" value="${toString:was.runtime}" />
    <property environment="env" />
    <property name="ear" value="${env.HOME}/IBM/rationalsdp7.0/workspace/mywebappDeploy/mywebappEAR.ear" />

    <target name="default" depends="deployEar">
    </target>

    <target name="generateWar" depends="compileWarClasses">
        <jar destfile="mywebapp.war">
            <fileset dir="../mywebapp/WebContent">
            </fileset>
        </jar>
    </target>

    <target name="compileWarClasses">
        <echo message="was_cp=${was_cp}" />
        <javac srcdir="../mywebapp/src" destdir="../mywebapp/WebContent/WEB-INF/classes" classpath="${was_cp}">
        </javac>
    </target>

    <target name="generateEar" depends="generateWar">
        <mkdir dir="./earbin/META-INF"/>
        <move file="mywebapp.war" todir="./earbin" />
        <copy file="../mywebappEAR/META-INF/application.xml" todir="./earbin/META-INF" />
        <jar destfile="${ear}">
            <fileset dir="./earbin" />
        </jar>
    </target>

    <!-- http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.javadoc.doc/public_html/api/com/ibm/websphere/ant/tasks/package-summary.html -->
    <target name="deployEar" depends="generateEar">
        <taskdef name="wsInstallApp" classname="com.ibm.websphere.ant.tasks.InstallApplication" classpath="${was_cp}"/>
        <wsInstallApp ear="${ear}" 
            failonerror="true" 
            debug="true" 
            taskname=""
            washome="${was_home}" />
    </target>

</project>

Notes:

  • You can only run this once! You cannot install if the app name is in use - see other tasks like wsUninstallApp
  • It probably won't start the app either
  • You need to run this on the server and the script is quite fragile

Alternatives

I would probably use Java Management Extensions (JMX). You could write a file-upload servlet that accepts an EAR and uses the deployment MBeans to deploy the EAR on the server. You would just POST the file over HTTP. This would avoid any WAS API dependencies on your dev/build machine and could be independent of any one project.

Botulinus answered 7/8, 2008 at 16:16 Comment(3)
Extra info & samples here: illegalargumentexception.blogspot.com/2008/08/…Botulinus
The WAS deployment JMX MBeans can't be used by a remote JSE app? (assuming libs on the classpath, of course)Coagulant
@Coagulant I don't know/remember - I wrote this ~5 years ago - but I assume you'd need to get the bytes over to the server to provide a local path to the AppManagement MBean anyway.Botulinus
F
6

Here is some of the same functionality if you don't have the WAS ant tasks available or don't want to run was_ant.bat. This relies on wsadmin.bat existing in the path.

<property name="websphere.home.dir" value="${env.WS6_HOME}" />
<property name="was.server.name" value="server1" />
<property name="wsadmin.base.command" value="wsadmin.bat" />

<property name="ws.list.command" value="$AdminApp list" />
<property name="ws.install.command" value="$AdminApp install" />
<property name="ws.uninstall.command" value="$AdminApp uninstall" />
<property name="ws.save.command" value="$AdminConfig save" />
<property name="ws.setManager.command" value="set appManager [$AdminControl queryNames cell=${env.COMPUTERNAME}Node01Cell,node=${env.COMPUTERNAME}Node01,type=ApplicationManager,process=${was.server.name},*]" />
<property name="ws.startapp.command" value="$AdminControl invoke $appManager startApplication" />
<property name="ws.stopapp.command" value="$AdminControl invoke $appManager stopApplication" />

<property name="ws.conn.type" value="SOAP" />
<property name="ws.host.name" value="localhost" />
<property name="ws.port.name" value="8880" />
<property name="ws.user.name" value="username" />
<property name="ws.password.name" value="password" />

<property name="app.deployed.name" value="${artifact.filename}" />
<property name="app.contextroot.name" value="/${artifact.filename}" />

<target name="websphere-list-applications">
    <exec dir="${websphere.home.dir}/bin" executable="${wsadmin.base.command}" output="waslist.txt" logError="true">
        <arg line="-conntype ${ws.conn.type}" />
        <arg line="-host ${ws.host.name}" />
        <arg line="-port ${ws.port.name}" />
        <arg line="-username ${ws.user.name}" />
        <arg line="-password ${ws.password.name}" />
        <arg line="-c" />
        <arg value="${ws.list.command}" />
    </exec>
</target>

<target name="websphere-install-application" depends="websphere-uninstall-application">
    <exec executable="${websphere.home.dir}/bin/${wsadmin.base.command}" logError="true" outputproperty="websphere.install.output" failonerror="true">
        <arg line="-conntype ${ws.conn.type}" />
        <arg line="-host ${ws.host.name}" />
        <arg line="-port ${ws.port.name}" />
        <arg line="-username ${ws.user.name}" />
        <arg line="-password ${ws.password.name}" />
        <arg line="-c" />
        <arg value="${ws.install.command} ${dist.dir}/${artifact.filename}.war {-appname ${app.deployed.name} -server ${was.server.name} -contextroot ${app.contextroot.name}}" />
        <arg line="-c" />
        <arg value="${ws.save.command}" />
        <arg line="-c" />
        <arg value="${ws.setManager.command}" />
        <arg line="-c" />
        <arg value="${ws.startapp.command} ${app.deployed.name}" />
        <arg line="-c" />
        <arg value="${ws.save.command}" />
    </exec>
    <echo message="${websphere.install.output}" />
</target>

<target name="websphere-uninstall-application">
    <exec executable="${websphere.home.dir}/bin/${wsadmin.base.command}" logError="true" outputproperty="websphere.uninstall.output" failonerror="false">
        <arg line="-conntype ${ws.conn.type}" />
        <arg line="-host ${ws.host.name}" />
        <arg line="-port ${ws.port.name}" />
        <arg line="-username ${ws.user.name}" />
        <arg line="-password ${ws.password.name}" />
        <arg line="-c" />
        <arg value="${ws.setManager.command}" />
        <arg line="-c" />
        <arg value="${ws.stopapp.command} ${app.deployed.name}" />
        <arg line="-c" />
        <arg value="${ws.save.command}" />
        <arg line="-c" />
        <arg value="${ws.uninstall.command} ${app.deployed.name}" />
        <arg line="-c" />
        <arg value="${ws.save.command}" />
    </exec>
    <echo message="${websphere.uninstall.output}" />
</target>

Flex answered 26/9, 2008 at 19:31 Comment(0)
A
5

a good start point, could be this maven pluggin, not for use it, or maybe yes, but this maven is build over ant task. If you see WAS5+Plugin+Mojo.zip\src\main\scripts\was5.build.xml

Or as said "McDowell", you can use "WebSphere Application Server (WAS) Ant tasks" but directly as ANT task.

<path id="classpath">
    <fileset file="com.ibm.websphere.v61_6.1.100.ws_runtime.jar"/>
</path>

<taskdef name="wsStartApp" classname="com.ibm.websphere.ant.tasks.StartApplication" classpathref="classpath" />
<taskdef name="wsStopApp" classname="com.ibm.websphere.ant.tasks.StopApplication" classpathref="classpath" />
<taskdef name="wsInstallApp" classname="com.ibm.websphere.ant.tasks.InstallApplication" classpathref="classpath" />
<taskdef name="wsUninstallApp" classname="com.ibm.websphere.ant.tasks.UninstallApplication" classpathref="classpath" />

<target name="startWebApp1" depends="installEar">
    <wsStartApp wasHome="${wasHome.dir}" 
                application="${remoteAppName}" 
                server="${clusterServerName}" 
                conntype="${remoteProdConnType}" 
                host="${remoteProdHostName}" 
                port="${remoteProdPort}" 
                user="${remoteProdUserId}" 
                password="${remoteProdPassword}" />
</target>

<target name="stopWebApp1" depends="prepare">
    <wsStopApp wasHome="${wasHome.dir}"
                application="${remoteAppName}"
                server="${clusterServerName}"
                conntype="${remoteConnType}"
                host="${remoteHostName}"
                port="${remotePort}"
                user="${remoteUserId}"
                password="${remotePassword}"/>
</target>

<target name="uninstallEar" depends="stopWebApp1">
    <wsUninstallApp wasHome="${wasHome.dir}"
                    application="${remoteAppName}"
                    options="-cell uatNetwork -cluster DOL"
                    conntype="${remoteConnType}"
                    host="${remoteHostName}"
                    port="${remoteDmgrPort}"
                    user="${remoteUserId}"
                    password="${remotePassword}"/>
</target>

<target name="installEar" depends="prepare">
    <wsInstallApp ear="${existingEar.dir}/${existingEar}" 
                  wasHome="${wasHome.dir}" 
                  options="${install_app_options}"
                  conntype="${remoteConnType}" 
                  host="${remoteHostName}" 
                  port="${remoteDmgrPort}" 
                  user="${remoteUserId}" 
                  password="${remotePassword}" />
</target>

Another useful link could be this.

Alodie answered 18/8, 2008 at 15:28 Comment(0)
S
0

If you just want to play around why not use the netbeans IDE to generate your ear files. If you create an enterprise project it will automatically generate the ant files for you. Good for prototyping and just getting started :-)

There is even a was plugin which allows automated deployment however this seems very shakey!

Shearwater answered 22/9, 2008 at 7:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.