如何使用ANT脚本在远程WebLogic服务器中部署配置文件,JARS和EAR文件



我想使用ANT脚本在远程WebLogic Server上部署JAR文件,配置文件和生成的EAR文件。

我创建了蚂蚁脚本,以停止WebLogic Server,删除旧文件(JAR,Config XML文件,EAR)将给定源复制到目标,此脚本在源和目标都在同一机器上时工作。

<project name="Svn" default="startserver">
<property name="bea.home" value="C:/Oracle/Middleware/Oracle_Home" />
<property name="weblogic.home" value="${bea.home}/wlserver" />
<property name="domain.home" value="${bea.home}/user_projects/domains" />
<property name="domain.name" value="NAPF_domain" />
<property name="host" value="10.254.5.191" />
<property name="port" value="7001" />
<property name="username" value="weblogic" />
<property name="password" value="weblogic" />
<property name="admin.server.name" value="AdminServer" />
<property name="libdeploy.dir" value="${domain.home}/${domain.name}/lib/" />
<property name="configdeploy.dir" value="${domain.home}/${domain.name}/pf-appl/config/" />
<property name="eardeploy.dir" value="${domain.home}/${domain.name}/servers/AdminServer/upload/" />
<property name="libsource.dir" value="napf-main/napf-build/release/target/Release/lib/" />
<property name="configsource.dir" value="napf-main/napf-build/release/target/Release/config/" />
<property name="earsource.dir" value="napf-main/napf-build/release/target/Release/dist/" />
<property name="napfscutitysource.dir" value="napf-main/napf-security-lib" />
<property name="sourceMonitorHome" location="NAPF_SERVER_SOURCE/SourceMonitor"/>
<path id="wls.classpath">
    <fileset dir="${weblogic.home}/server/lib">
        <include name="web*.jar" />
    </fileset>
</path>
<taskdef name="wlserver" classname="weblogic.ant.taskdefs.management.WLServer" classpathref="wls.classpath" />
<target name="start-server">
    <wlserver dir="${domain.home}/${domain.name}" host="${host}" port="${port}" domainname="${domain.name}" servername="${admin.server.name}" action="start" username="${username}" password="${password}" beahome="${bea.home}" weblogichome="${weblogic.home}" verbose="true" noexit="true" protocol="t3" classpath="${weblogic.home}/server/lib/weblogic.jar">
        <jvmarg value="-server" />
        <jvmarg value="-Xms256m" />
        <jvmarg value="-Xmx512m" />
        <jvmarg value="-XX:PermSize=128m" />
        <jvmarg value="-XX:MaxPermSize=256m" />
    </wlserver>
    <sleep seconds="2" />
</target>
<target name="stop-server">
    <wlserver dir="${domain.home}/${domain.name}" host="${host}" port="${port}" servername="${admin.server.name}" username="${username}" password="${password}" action="shutdown" beahome="${bea.home}" weblogichome="${weblogic.home}" forceshutdown="true" />
</target>
<target name="purge-deploy" description="Delete old deploy files.">
    <echo message="Deleting old deploy files..." />
    <delete includeEmptyDirs="true">
        <!-- Delete all jar files  -->
        <fileset dir="${libdeploy.dir}" includes="**/*" />
        <!-- Delete all config files  -->
        <fileset dir="${configdeploy.dir}" includes="**/*" />
    </delete>
</target>
<target name="copyToSecurityLib" description="Copy files to napf security folder.">
    <copy todir="${libdeploy.dir}">
        <fileset dir="${napfscutitysource.dir}">
            <include name="**" />
            <!-- ignore files/folders starting with svn -->
            <exclude name="**/.svn" />
        </fileset>
    </copy>
</target>
<target name="copyToDeploy" description="Copy files to deploy folder.">
    <copy todir="${libdeploy.dir}">
        <fileset dir="${libsource.dir}">
            <include name="**" />
            <!-- ignore files/folders starting with svn -->
            <exclude name="**/.svn" />
        </fileset>
    </copy>
    <copy todir="${configdeploy.dir}">
        <fileset dir="${configsource.dir}">
            <include name="**" />
            <!-- ignore files/folders starting with svn -->
            <exclude name="**/.svn" />
        </fileset>
    </copy>
    <copy todir="${eardeploy.dir}">
        <fileset dir="${earsource.dir}">
            <include name="**" />
            <!-- ignore files/folders starting with svn -->
            <exclude name="**/.svn" />
        </fileset>
    </copy>
</target>
<target name="purgeReport" description="Delete old report files.">
    <echo message="Deleting old report files..." />
    <delete includeEmptyDirs="true">
        <fileset dir="${sourceMonitorHome}" includes="**/*.csv,*.jpeg,*.smp" />
    </delete>
</target>
<target name="startSourceMonitor">
    <exec dir="${sourceMonitorHome}" executable="cmd" failonerror="true" spawn="false">
      <arg value="/c"/>
      <arg value="sourcemonitor.bat"/>
    </exec>
</target>
<target name="copyReportFiles" description="Copy files to napf source directory to slave workspace directory.">
    <delete includeEmptyDirs="true">
        <fileset dir="${sourceMonitorWorkSpace}"/>
    </delete>
    <mkdir dir="${sourceMonitorWorkSpace}"/>
     <sleep seconds="1" />
    <copy todir="${sourceMonitorWorkSpace}">
        <fileset dir="${sourceMonitorHome}">
            <include name="**/*.csv" />
             <include name="**/*.jpeg" />
            <exclude name="**/.svn" />
        </fileset>
    </copy>
</target>

请建议。

您可以尝试 wldeploy ant任务。

首先,添加任务定义。

<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy">
    <classpath>
        <pathelement location="${weblogic.home}/server/lib/weblogic.jar"/>
    </classpath>
</taskdef>

接下来,配置wldeploy任务的每个动作,例如部署,重新部署或非剥削。

示例,

<!-- The deployment name for the deployed application.
If you do not specify this attribute, WebLogic Server assigns a deployment name to the application, based on its archive file or exploded directory. -->
<property name="deploy.name" value="MyApp"/>
<!-- The archive file or exploded directory to deploy. -->
<property name="deploy.source" value="MyApp.ear"/>
<!-- The list of target servers to which the application is deployed.
The value of this attribute is a comma-separated list of the target servers, clusters, or virtual hosts.
If you do not specify a target list when deploying an application, the target defaults to the Administration Server instance. -->
<property name="deploy.targets" value="MyCluster"/>
<!-- Deploying Applications  -->
<target name="deploy">
<wldeploy action="deploy" 
          name="${deploy.name}"
          user="${username}"
          password="${password}"
          remote="true"
          adminurl="t3://${host}:${port}"
          source="${deploy.source}"
          targets="${deploy.targets}"/>
</target>
<!-- Redeploying Applications  -->
<target name="redeploy">
<wldeploy action="redeploy"
          name="${deploy.name}"
          user="${username}"
          password="${password}"
          remote="true"
          adminurl="t3://${host}:${port}"
          targets="${deploy.targets}"/>
</target>
<!-- Undeploying Applications  -->
<target name="undeploy">
<wldeploy action="undeploy"
          name="${deploy.name}"
          failonerror="false"
          user="${username}"
          password="${password}"
          remote="true"
          adminurl="t3://${host}:${port}" 
          targets="${deploy.targets}"/>
</target>

请注意,如果我们要将jar或ear部署到远程weblogic服务器,我们必须明确将远程 wldeploy标签中的属性设置为true,因为默认值为false。

有关该任务的更完整的参考可以在https://docs.oracle.com/cd/e12839_01/web.1111/e13706/wldeploy.htm

如果您只是指定远程服务器文件路径,则上述任务将有效。本质上,您需要两个参数,一个是远程,另一个是上传的。同样的工作也可以,但是如果您从远程服务器部署

,我看到该任务缺少一个参数。
<target name="deploy1">
<wldeploy action="deploy"
      upload="true"
      remote="true"
          name="${deploy.name.1}"
          source="${deploy.source.1}"
          user="${wls.username}"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>

相关内容

  • 没有找到相关文章

最新更新