ANT发布应用的框架

应用的开发如有一个好的结构,给程序的开发及发布带来便捷,一点总结:

1、文件夹的结构:
ant.properties  :存放每个业务模块的ant打包属性文件。
              IHC0100.properties
Build         :存放打包后的文件,ant打包时会自动生成。
              build.xml
              createJar.bat
              deploy.bat
Doc          :生成的doc文件。
js           :存放jsp的js文件。
jsp          :存放jsp文件。
src          :存放程序的原文件。
CSS          :存放jsp的css文件。
deploy        :打包用的build文件。
ear          :打包时用的配置文件,包括application.xml及manifest文件。
jar          :打包时用的配置文件,包括EJB的配置文件。
war          :打包时用的配置文件,包括web.xml及manifest文件。
WEB-INF     :打包时用的配置文件。

2、IHC0100.properties的文件内容:
    subroot=IHC

3、createJar.bat的文件内容:
    @echo off

    REM No.1  1.1  Test1 (IHC0100)
    REM echo IHC0100.jar Creating....
    call ant jar -Did=IHC0100

    REM No.2  1.2  test2 (IHC0200)
    REM echo IPAN0200.jar Creating....
    REM call ant jar -Did=IPAN0200

4、deploy.bat的文件内容:
    @echo off

    echo The application is uninstalled from WAS丅
    call %WAS_HOME%\bin\wsadmin -conntype none -c "$AdminApp uninstall %2"

    echo The application is installed in WAS丅
    call %WAS_HOME%\bin\wsadmin -conntype none -c "$AdminApp install %1%2.ear {-usedefaultbindings -defaultbinding.ejbjndi.prefix %2 -defaultbinding.force -useMetaDataFromBinary -deployejb -deployejb.dbtype ORACLE_V9I -server APP_SERVER}"

5、build.xml的文件内容:
<project name="MyProject" default="ear" basedir=".">
    <description>
        QGBIHC example build file
    </description>
    <!--Mayby should change the following property -->
    <property name="sourceDir"      value="F:/workspace/ihc/test"/>
    <property name="appname"        value="test"/>
  
    <!--Gobal property -->
    <property name="src"            value="${sourceDir}/src"/>
    <property name="doc"           value="${sourceDir}/doc"/>
    <property name="build"          value="${sourceDir}/build"/>
    <property name="weblib"        value="${sourceDir}/WEB-INF/lib"/>
    <property name="classes"      value="${sourceDir}/WEB-INF/classes"/>
    <property name="dist"           value="dist"/>
  
    <property environment="env"/>
    <property name="WAS"          value="${env.WAS_HOME}"/>
  
    <property file="${sourceDir}/ant.properties/${id}.properties"/>
  
    <target name="init">
        <!-- Create the time stamp -->
        <tstamp/>
        <mkdir dir="${build}"/>
        <mkdir dir="${classes}"/>
    </target>

    <target name="compile" depends="init" >
        <echo message="${id} Compile"/>
        <javac srcdir="${src}"
             destdir="${classes}"
             classpath="${classes};
                      ${weblib}/struts.jar;
                      ${weblib}/poi.jar;
                      ${weblib}/xercesImpl.jar;
                      ${weblib}/xmlParserAPIs.jar;
                      ${weblib}/classes12.jar;
                      ${WAS}/lib/j2ee.jar;
                      "
            debug="on"
            optimize="on"
            deprecation="on">
            <include name="org/**/*.java"/>
        </javac>
    </target>

    <!-- Jar-file Make -->
    <target name="jar" depends="compile">
        <mkdir dir="${build}"/>
        <jar jarfile="${build}/${id}.jar" compress="yes"
            manifest="${sourceDir}/Jar/test/${subroot}/${id}/EJB/META-INF/${id}.mf">
            <metainf dir="${sourceDir}/Jar/test/${subroot}/${id}/EJB/META-INF">
                <include name="*.xml"/>
            </metainf>
            <fileset dir="${classes}/"
                  includes="org/ihc/test/${subroot}/${id}/**/*.class"
                  excludes="org/ihc/test/${subroot}/${id}/excel/**
                           ,org/ihc/test/${subroot}/${id}/framework/**
                           ,org/ihc/test/${subroot}/${id}/pdf/**
                           ,org/ihc/test/${subroot}/${id}/taglib/**"/>
        </jar>
    </target>
  
    <!-- All Jar-file Make -->
    <target name="jar_project">
        <exec executable="cmd.exe">
            <arg line= "/C createjar.bat"/>
        </exec>
    </target>
  
    <!--  War-file Make -->
    <target name="war" depends="jar_project">
        <war warfile="${build}/${appname}.war"
            webxml="${sourceDir}/War/test/test/WEB-INF/web.xml"
            manifest="${sourceDir}/War/test/test/META-INF/${appname}.mf">
            <fileset dir="${sourceDir}/">
            <include name="CSS/*.css"/>
            <include name="image/*.*"/>
            <include name="js/*.js"/>
            <include name="jsp/*.html"/>
            <include name="jsp/test/**/*.jsp"/>
            <include name="jsp/test/**/*.js"/>
            <include name="jsp/test/**/*.css"/>
            <include name="WEB-INF/*.tld"/>
            <include name="WEB-INF/*.xml"/>
            <include name="WEB-INF/*.dtd"/>
            <exclude name="WEB-INF/web.xml"/>
        </fileset>
        <zipfileset dir="${classes}"
            includes="org/ihc/test/**/excel/**/*.class
                      ,org/ihc/test/**/framework/**/*.class
                      ,org/ihc/test/**/taglib/**/*.class" prefix="WEB-INF/classes"/>
        <zipfileset dir="${weblib}/"
             includes="struts.jar
                      ,classes12.jar
                      ,modelism.jar
                      ,xercesImpl.jar,
                      ,xmlParserAPIs.jar,
                      ,poi.jar" prefix="WEB-INF/lib"/>
        </war>
    </target>
  
    <!--  Ear-file Make -->
    <target name="ear" depends="war">
        <ear earfile="${build}/${appname}.ear"
            appxml="${sourceDir}/Ear/test/test/META-INF/application.xml"
            manifest="${sourceDir}/Ear/test/test/META-INF/${appname}.mf"
            update="yes">
            <fileset dir="${build}/"
                    includes="*.jar
                    ,*.war"/>
        </ear>
    </target>
  
    <!-- Application Install -->
    <target name="deploy" depends="ear">
        <copy todir="${WAS}/installableApps" file ="${build}/${appname}.ear" />
        <exec executable="cmd.exe">
            <arg line= "/C deploy.bat"/>
            <arg value= "${build}/"/>
            <arg value= "${appname}"/>
        </exec>
    </target>

    <target name="clean"
        description="clean up" >
        <delete>
            <fileset dir="${build}" includes="*.jar, *.war, *.ear"/>
        </delete>
        <delete dir="${doc}"/>
    </target>

    <target name="doc">
        <mkdir dir="${doc}"/>
        <javadoc destdir="${doc}"
                   author="true"
                   version="true"
                   use="true"
                   sourcepath="${src}"
                   packagenames="org.ihc.test.*"
                 >
            <doctitle><![CDATA[<h1>${appname}</h1>]]></doctitle>
            <bottom><![CDATA[<i>Copyright &#169; 2000 Dummy Corp. All Rights Reserved.</i>]]></bottom>
            <tag name="todo" scope="all" description="To do:" />
            <group title="IPAN Packages" packages="org.ihc.test.IPAN.*"/>
            <group title="MENT Packages" packages="org.ihc.test.MENT.*"/>
        </javadoc>
    </target>
    
    <target name="help">
        <echo>
      -- Necessary Environment Variable--
      WAS_HOME         : WebSphere Application Server's DIR

      -- For function unit (each function ID)--
      ant jar  -Did=[function ID]   : Make jar-file

      -- For the whole --
      ant compile      : Compile java-file
      ant war          : Make war-file
      ant ear          : Make ear-file
      ant deploy       : Make and deploy Application  
      ant doc          : Make javadoc
      
      ant clean        : Clear class/jar/war/ear
      ant help         : Help message
        </echo>
    </target>

</project>

你可能感兴趣的:(框架,jsp,Web,css,ant)