如何使用ant脚本在远程weblogic服务器中部署配置文件,jar和ear文件

时间:2017-11-27 10:27:46

标签: ant weblogic12c

我想使用ant脚本在远程weblogic服务器上部署jar文件,配置文件和生成的ear文件。

我创建了停止weblogic服务器的ant脚本,删除旧文件(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>

请建议。

2 个答案:

答案 0 :(得分:2)

您可以尝试 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

上找到

答案 1 :(得分:0)

如果仅指定远程服务器文件路径,则上述任务将起作用。本质上,您将需要两个参数,一个是远程参数,另一个是上传参数。 相同的方法也可以,但是如果您从远程服务器进行部署,我会看到该任务缺少参数

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