22

我试图说服我的供应商使用 ANT 而不是 Rational Application Development,这样任何人都可以随时随地重新编译、重新检查、重新部署解决方案。:P

我为一个生成 JAR 文件但停在那里的项目启动了 build.xml,我需要真实的示例来比较笔记。我的好朋友们!我身边没有人可以聊这个!

到目前为止,这是我的build.xml 。

(*) 我根据使用 pastebin.ca的建议编辑了我的问题

4

4 回答 4

14

我的环境:Fedora 8;WAS 6.1(与 Rational Application Developer 7 一起安装)

该领域的文档非常差,并且缺乏实际示例。

使用 WebSphere Application Server (WAS) Ant 任务

要按照此处所述运行,您需要使用ws_ant.shws_ant.bat命令从服务器配置文件bin 目录运行它们。

<?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>

命令:

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

部署脚本

<?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>

笔记:

  • 您只能运行一次!如果应用名称正在使用中,则无法安装 - 请参阅wsUninstallApp等其他任务
  • 它可能也不会启动应用程序
  • 您需要在服务器上运行它,并且脚本非常脆弱

备择方案

我可能会使用 Java 管理扩展 (JMX)。您可以编写一个接受 EAR 并使用部署 MBean 在服务器上部署 EAR 的文件上传 servlet。您只需通过 HTTP 发布文件。这将避免您的开发/构建机器上的任何 WAS API 依赖项,并且可以独立于任何一个项目。

于 2008-08-07T16:16:00.010 回答
6

如果您没有可用的 WAS ant 任务或不想运行 was_ant.bat,这里有一些相同的功能。这依赖于路径中存在的 wsadmin.bat。

<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>

于 2008-09-26T19:31:42.253 回答
5

一个好的起点,可能是这个maven 插件,不是为了使用它,或者可能是的,但是这个 maven 是建立在 ant 任务之上的。如果您看到 WAS5+Plugin+Mojo.zip\src\main\scripts\was5.build.xml

或者如“McDowell”所说,您可以使用“WebSphere Application Server (WAS) Ant 任务”但直接作为 ANT 任务。

<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>

另一个有用的链接可能是这个

于 2008-08-18T15:28:40.953 回答
0

如果您只是想玩玩,为什么不使用 netbeans IDE 来生成您的 ear 文件。如果您创建企业项目,它将自动为您生成 ant 文件。适合原型设计和刚刚开始:-)

甚至还有一个允许自动部署的插件,但这看起来很不稳定!

于 2008-09-22T07:51:19.750 回答