用于Web和应用程序部署的Ant脚本构建

时间:2015-01-21 04:06:37

标签: java ant weblogic

我正在开发一个动态的Web项目。 当我想用ant脚本构建它时,我有问题。 我的目的是采用三层概念,即在不同的机器中具有业务层和表示层。 我使用weblogic服务器作为Web服务器(表示层)和app服务器(业务层)

这是我的build.xml:

<property name="build" value="./build" />
<property name="dist" value="./dist" />
<!-- <property name="conf" value="./config" /> -->
<property name="src" value="./src" />
<property name="web" value="./WebContent" />
<property name="lib" value="${web}/WEB-INF/lib" />
<property name="webinf" value="${web}/WEB-INF" />
<property name="metainf" value="${web}/META-INF" />
<property name="servletLib" value="C:\Oracle\MiddlewareOneBC\wlserver_12.1\server\lib" />
<property name="deploydir" value="C:\Oracle\MiddlewareOneBC\user_projects\domains\OneBCDomain\autodeploy" />
<property name="project.name" value="OneBCApplication" />

<path id="build.classpath">
    <fileset dir="${lib}" includes="**/*.jar" />
    <fileset dir="${servletLib}" includes="**/*.jar" />
</path>

<target name="clean">
    <delete dir="${build}" />
    <delete dir="${dist}" />
</target>

<target name="init">
    <tstamp />
    <mkdir dir="${build}" />
    <mkdir dir="${build}/classes" />
    <mkdir dir="${dist}" />
</target>

<target name="compile" depends="init">
    <javac srcdir="${src}" destdir="${build}/classes" optimize="on" includeantruntime="false">
        <classpath refid="build.classpath" />
    </javac>
    <copy todir="${build}/classes">
        <fileset dir="${src}" excludes="ddl/*" />
        <fileset dir="${src}" excludes="dml/*" />
        <fileset dir="${src}" excludes="**/*.xls" />
        <fileset dir="${src}" includes="**/*.xml" />
        <fileset dir="${src}" includes="**/*.properties" />
        <!-- <fileset dir="${conf}" includes="**/*" /> -->
    </copy>
</target>

<target name="war" depends="compile">
    <war destfile="${dist}/${project.name}.war" webxml="${webinf}/web.xml">
        <lib dir="${lib}" />
        <classes dir="${build}/classes"/>
        <fileset dir="${web}">
            <include name="**/*.*" />
            <exclude name="WEB-INF/lib/*" />
        </fileset>
    </war>
</target>

<target name="ear" depends="war">
    <ear destfile="${dist}/${project.name}EAR.ear" appxml="${metainf}/application.xml">
        <fileset dir="${dist}" includes="*.war" />
    </ear>
</target>

<target name="warweb" depends="compile">
    <war destfile="${dist}/web/${project.name}Web.war" webxml="${webinf}/web.xml">
        <lib dir="${lib}" excludes="**/BV_*.*" />
        <classes dir="${build}/classes">
            <!-- <exclude name="**/*.java"/>
            <exclude name="**/*.class"/> -->
            <exclude name="com/**"/>
        </classes>

        <fileset dir="${web}">
            <include name="**/*.*" />
            <exclude name="WEB-INF/lib/*" />
        </fileset>
    </war>
     <jar destfile="${dist}/lib/${project.name}.jar" basedir="${build}/classes"/>
</target>

<target name="earweb" depends="warweb">
    <ear destfile="${dist}/${project.name}Static.ear" appxml="${metainf}/application.xml">
        <fileset dir="${dist}/web" includes="*.war" />
    </ear>
</target>

    <target name="earapp" depends="warweb">
    <ear destfile="${dist}/${project.name}App.ear" appxml="${metainf}/application.xml">
        <fileset dir="${dist}/web" includes="*.war" />
        <zipfileset dir="${dist}/lib" includes="*.jar" prefix="APP-INF/lib" />
        <zipfileset dir="${lib}" includes="**/BV_*.*" prefix="APP-INF/lib" />           
    </ear>
</target>



<target name="deploywar" depends="ear">
    <copy todir="${deploydir}">
        <fileset dir="${dist}" includes="*.war" />
    </copy>
</target>

<target name="deployear" depends="ear">
    <copy todir="${deploydir}">
        <fileset dir="${dist}" includes="*.ear" />
    </copy>
</target>

<target name="undeploy">
    <delete file="${deploydir}/${project.name}EAR.ear"/>
    <delete file="${deploydir}/${project.name}EAR.war"/>
</target>

如何单独构建它?以及表示层的请求如何与业务层通信? weblogic中是否有任何配置必须完成这两个层的通信? 提前谢谢。

1 个答案:

答案 0 :(得分:2)

使用文件集任务,您可以指定要包含在应用服务器或Web服务器中的jar文件。

    <ear destfile="${build.dir}/myapp.ear" appxml="${src.dir}/metadata/application.xml">
     <fileset dir="${build.dir}" includes="*.jar,*.war"/>
    </ear>

只需要两个耳朵任务就可以为app服务器创建两个耳朵,为Web服务器创建一个耳朵。