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
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:
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With