程序员人生 网站导航

产品打包工具的制作,ant,编译源码,打jar包,打tag,打war包,备份release版本等

栏目:综合技术时间:2016-06-23 08:49:22

1、  在进行打包工具的制作前,需要准备的软件有:

svnant⑴.3.1

作用是让ant和svn相干联

apache-ant⑴.9.7

需要设置ant_home,path,我的配置是:

ANT_HOME = D:\kaipu\cms4all\app-tpl-pack\apache-ant⑴.9.7

Path = %ANT_HOME%\bin

2、准备好上面的操作以后,找个英文的目录,比如:D:\kaipu\cms4all\app-tpl-pack,在目录下创建两个文件build.xml和build.properties,并把上面的svnant⑴.3.1和apache-ant⑴.9.7一样放到相同目录下,最后的目录以下:

3、编写build.xml文件

<?xml version="1.0" encoding="UTF⑻"?>

<!--default="dist"表示当只履行ant的时候,默许履行下面的dist命令-->

<project name="tpl-release" basedir="." default="dist">

    <!--表示build.xml中引入的变量是从build.properties中取得的-->

         <property file="build.properties" />

         <tstamp>

                   <format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" locale="zh" />

         </tstamp>

         <tstamp>

                   <format property="date" pattern="yyyyMMdd" locale="zh" />

         </tstamp>

         <!--ant要和svn相干联,需要配置1个svnant,下面表示相干的内容依赖svnant-->

         <path id="svn.classpath">

                   <fileset dir="${svnant.dir}/lib">

                            <include name="**/*.jar" />

                   </fileset>

         </path>

         <path id="depends.classpath">

                   <fileset dir="${java.depends.lib.dir}">

                            <include name="**/*.jar" />

                   </fileset>

         </path>

         <!--援用 svnantlib.xml ,其中定义了ANT的SVN命令,见下方详解。-->

         <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="svn.classpath" />

         <!--<taskdef name="yui-compressor" classname="net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask" classpathref="depends.classpath"></taskdef>-->

 

         <!--通过ant clean命令能够清除dir.source、dir.compile和dir.release这些文件夹-->

         <target name="clean">

                   <echo message="delete all dirs ..." />

                   <delete dir="${dir.source}" />

                   <delete dir="${dir.compile}" />

                   <delete dir="${dir.release}" />

         </target>

 

         <!--定义svnSetting ,新的设置SVN属性方式-->

         <!-- 通过JAVAHL模式(即设置为TRUE),而不是SVNKIT模式 -->

         <svnSetting id="svn.settings" svnkit="true" javahl="false" username="${svn.user}" password="${svn.pass}" />

         <svnSetting id="svn.settings.1" svnkit="true" javahl="false" username="${svn.user}" password="${svn.pass}" failonerror="false" />

 

         <!-- 导出源代码,导出的进程中是从svn上checkout下来的,履行的命令是:ant export-source-->

         <target name="export-source">

                   <echo message="export source" />

                   <mkdir dir="${dir.source}" />

                   <svn refid="svn.settings">

                            <export srcUrl="${trunk.url}/${proj.app-tpl-api}" destPath="${dir.source}/${proj.app-tpl-api}" revision="HEAD" />                  

                            <export srcUrl="${trunk.url}/${proj.app-tpl-impl}" destPath="${dir.source}/${proj.app-tpl-impl}" revision="HEAD"/>

                            <export srcUrl="${trunk.url}/${proj.app-tpl-webapp}" destPath="${dir.source}/${proj.app-tpl-webapp}" revision="HEAD"/>

                   </svn>

         </target>

        

         <!--从tag版本创建tag,在svn上打上标记-->

         <target name="create-tag-from-trunk">

                   <svn refid="svn.settings.1">

                            <delete url="${tags.url}/${tag.version.label}" message="tags duplicate!" />

                   </svn>

                   <echo message="create tags ${tag.version.label}" />

                   <svn refid="svn.settings">

                            <mkdir url="${tags.url}/${tag.version.label}" message="Tag created by tuzq on ${TODAY}" />

                            <copy srcUrl="${trunk.url}/${proj.app-tpl-api}" destUrl="${tags.url}/${tag.version.label}" message="Tag created by toto on ${TODAY}" />

                            <copy srcUrl="${trunk.url}/${proj.app-tpl-impl}" destUrl="${tags.url}/${tag.version.label}" message="Tag created by toto on ${TODAY}" />

                            <copy srcUrl="${trunk.url}/${proj.app-tpl-webapp}" destUrl="${tags.url}/${tag.version.label}" message="Tag created by toto on ${TODAY}" />

                   </svn>

         </target>

 

         <!--编译api代码-->

         <target name="compile-app-tpl-api">

                   <echo message="compile app-tpl-api project" />

                   <!--javac,编译,对应java中的javac命令,其中srcdir定义源文件路径  destdir定义编译文件路径

                   includeantruntime作用是指定编译任务是不是包括ant的classpath,可有可无,不影响编译,但不写可能会出现正告,为了眼不见心不烦,加上吧

                   -->

                   <delete dir="${dir.compile}/${proj.app-tpl-api}"/>

                   <mkdir dir="${dir.compile}/${proj.app-tpl-api}"/>

                   <javac srcdir="${dir.source}/${proj.app-tpl-api}${java.source.path}" destdir="${dir.compile}/${proj.app-tpl-api}" debug="${option.compile.debug}" optimize="${option.compile.optimize}" deprecation="${option.compile.deprecation}" encoding="${option.compile.encoding}" target="${option.compile.target}" verbose="${option.compile.verbose}" includeantruntime="false">

                            <classpath>

                                <!--依赖的lib包下的jar文件-->

                                     <fileset dir="${java.depends.lib.dir}">

                                               <include name="**/*.jar" />

                                     </fileset>

                                     <!--依赖的tomcat中的jar文件-->

                                     <fileset dir="${tomcat.lib.dir}">

                                               <include name="**/*.jar" />

                                     </fileset>

                            </classpath>

                   </javac>

         </target>

        

         <!--通过ant命令进行打包,打成的包是:app-tpl-api⑴.0-SNAPSHOT.jar-->

         <target name="app-tpl-api-jar" description="make jar file">

                   <delete dir="${dir.compile}/${proj.app-tpl-api}/${tpl.jar.app-tpl-api}"/>

                   <property name="app-tpl-api-jar-filename" value="${dir.compile}/${proj.app-tpl-api}/${tpl.jar.app-tpl-api}" />

                   <jar jarfile="${app-tpl-api-jar-filename}" basedir="${dir.compile}/${proj.app-tpl-api}">

                       <!--为jar包指定manifest,如果jar包不需要打成runnable的情势,manifest可以不要-->

                   </jar>

         </target>

        

         <!--编译app-tpl-impl.jar文件-->

         <target name="compile-app-tpl-impl">

                   <echo message="compile app-tpl-api project" />

                   <!--javac,编译,对应java中的javac命令,其中srcdir定义源文件路径  destdir定义编译文件路径

                   includeantruntime作用是指定编译任务是不是包括ant的classpath,可有可无,不影响编译,但不写可能会出现正告,为了眼不见心不烦,加上吧

                   -->

                   <delete dir="${dir.compile}/${proj.app-tpl-impl}"/>

                   <copy file="${dir.compile}/${proj.app-tpl-api}/${tpl.jar.app-tpl-api}" todir="${java.depends.lib.dir}"/>

                   <mkdir dir="${dir.compile}/${proj.app-tpl-impl}"/>

                   <copydir dest="${dir.compile}/${proj.app-tpl-impl}" src="${dir.source}/${proj.app-tpl-impl}${proj.app-tpl-impl-mapper}">

                            <include name="sqlmaps/**" />

                   </copydir>

                   <javac srcdir="${dir.source}/${proj.app-tpl-impl}${java.source.path}" destdir="${dir.compile}/${proj.app-tpl-impl}" debug="${option.compile.debug}" optimize="${option.compile.optimize}" deprecation="${option.compile.deprecation}" encoding="${option.compile.encoding}" target="${option.compile.target}" verbose="${option.compile.verbose}" includeantruntime="false">

                            <classpath>

                                     <fileset dir="${java.depends.lib.dir}">

                                               <include name="**/*.jar" />

                                     </fileset>

                                     <fileset dir="${tomcat.lib.dir}">

                                               <include name="**/*.jar" />

                                     </fileset>

                            </classpath>

                   </javac>

         </target>

        

         <!--打包命令,打成的包是:app-tpl-impl⑴.0-SNAPSHOT.jar-->

         <target name="app-tpl-impl-jar" description="make jar file">

                   <delete dir="${dir.compile}/${proj.app-tpl-impl}/${tpl.jar.app-tpl-impl}"/>

                   <property name="app-tpl-impl-jar-filename" value="${dir.compile}/${proj.app-tpl-impl}/${tpl.jar.app-tpl-impl}" />

                   <jar jarfile="${app-tpl-impl-jar-filename}" basedir="${dir.compile}/${proj.app-tpl-impl}">

                       <!--为jar包指定manifest,如果jar包不需要打成runnable的情势,manifest可以不要-->

                   </jar>

         </target>

        

         <!-- 需要参数proj.name,主要是编译web工程 -->

         <target name="compile-app-tpl-webapp">

                   <echo message="compile web project ${tpl.war.app-tpl-webapp}" />

                   <property name="targetpath" value="${dir.compile}/${proj.app-tpl-webapp}" />

                   <property name="sourcepath" value="${dir.source}/${proj.app-tpl-webapp}" />

                   <!-- 编译swf web工程 -->

                   <mkdir dir="${targetpath}" />

                   <mkdir dir="${targetpath}WEB-INF/classes" />

                   <copy file="${dir.compile}/${proj.app-tpl-impl}/${tpl.jar.app-tpl-impl}" todir="${java.depends.lib.dir}"/>

                   <copy todir="${targetpath}" overwrite="true" preservelastmodified="true">

                            <fileset dir="${sourcepath}${web.source.path}" />

                   </copy>

                  

                   <javac srcdir="${sourcepath}${java.source.path}" destdir="${targetpath}WEB-INF/classes"

                            debug="${option.compile.debug}" optimize="${option.compile.optimize}" deprecation="${option.compile.deprecation}"

                            encoding="${option.compile.encoding}"

                            target="${option.compile.target}" verbose="${option.compile.verbose}" includeantruntime="false">

                            <classpath>

                                     <fileset dir="${java.depends.lib.dir}">

                                               <include name="**/*.jar" />

                                     </fileset>

                                     <fileset dir="${tomcat.lib.dir}">

                                               <include name="**/*.jar" />

                                     </fileset>

                            </classpath>

                   </javac>

                  

                   <copy todir="${targetpath}WEB-INF/classes" overwrite="true" preservelastmodified="true">

                            <fileset dir="${sourcepath}${config.source.path}" />

                   </copy>

                   <copy todir="${targetpath}WEB-INF/lib" overwrite="true" preservelastmodified="true">

                       <fileset dir="${java.depends.lib.dir}" />

                   </copy>

         </target>

        

         <!-- 需要war的名称 war.name -->

         <target name="war.app-tpl-webapp">

                   <delete dir="${dir.compile}/${tpl.war.app-tpl-webapp}"/>

                   <war warfile="${dir.compile}/${tpl.war.app-tpl-webapp}" webxml="${dir.compile}/${proj.app-tpl-webapp}/WEB-INF/web.xml">

                            <fileset dir="${dir.compile}/${proj.app-tpl-webapp}"/>

                   </war>

         </target>

        

         <!-- 发布相干工程及依赖工具包,通过ant dist命令,可以1次性履行清除、checkout源码、打tag、编译、打jar、打war包等操作 -->

         <target name="dist" depends="clean,export-source,create-tag-from-trunk,compile-app-tpl-api,app-tpl-api-jar,compile-app-tpl-impl,app-tpl-impl-jar,compile-app-tpl-webapp,war.app-tpl-webapp">

         <!--<target name="dist" depends="compile-app-tpl-api,app-tpl-api-jar,compile-app-tpl-impl,app-tpl-impl-jar,compile-app-tpl-webapp,war.app-tpl-webapp">-->

         <!-- <target name="dist" depends="create-tag-from-trunk">-->

                   <!-- target name="dist" -->

                   <!-- 编译 -->

                   <!-- compile-web-proj proj.swf,proj.jod,proj.imagemagick-->

         </target>

        

    <!--将需要relase的东西copy到dist目录下-->

         <target name="copy-to-dist">

                   <mkdir dir="${dir.release}/${app-tpl.name}" />

                   <copy todir="${dir.release}/${app-tpl.name}" overwrite="true" preservelastmodified="true" includeEmptyDirs="false">

                            <!-- copy war文件  -->

                            <fileset file="${dir.compile}/${tpl.war.app-tpl-webapp}" />

                   </copy>

         </target>

        

         <!--将所有的dist里面的东西放到svn上的release包中-->

         <target name="commit-release">

                   <!-- 提交到release库中 -->

                   <echo message="commit to release repository."/>

                   <svn refid="svn.settings.1">

                            <delete url="${release.url}/${tag.version.label}" message="Release duplicate!"/>

                   </svn>

                   <svn refid="svn.settings">

                            <mkdir url="${release.url}${tag.version.label}" message="Release created by tuzq on ${TODAY}" />

                            <import url="${release.url}${tag.version.label}" path="${dir.release}" message="Release created by tuzq on ${TODAY}" />

                   </svn>

         </target>

</project>

4、编写build.properties文件

#svn的相干属性

svn.user=这里填写svn的用户名

svn.pass=这里填写svn的用户名和密码

svnant.dir=D:/kaipu/cms4all/app-tpl-pack/svnant⑴.3.1

 

#打tag时的版本信息

tag.version.label=app-tpl-v1.0.0

branch.version.label=app-tpl-v1.0.0

 

java.depends.lib.dir=./lib

#java.compile.lib.dir=D:/app/alfresco/tomcat⑺.0.32/webapps/alfresco/WEB-INF/lib

tomcat.lib.dir=./tomcatlib

 

#svn服务器上的相干代码位置

trunk.url=这里放svn上trunk版本的url地址

tags.url=这里放svn上tag版本的url地址

branches.url=这里放branches版本的url地址

release.url=这里放置release版本的url地址

#相干工程的信息

proj.app-tpl-api=app-tpl-api/

proj.app-tpl-impl=app-tpl-impl/

proj.app-tpl-impl-mapper=src/main/resources

proj.app-tpl-webapp=app-tpl-webapp/

 

tpl.jar.app-tpl-api=app-tpl-api⑴.0-SNAPSHOT.jar

tpl.jar.app-tpl-impl=app-tpl-impl⑴.0-SNAPSHOT.jar

tpl.war.app-tpl-webapp=app-tpl-webapp.war

 

#本地编译及发布的目录结构

dir.source=./source

 

java.source.path=src/main/java

web.source.path=src/main/webapp

config.source.path=src/main/resources

 

#java的编译选项

option.compile.encoding=utf⑻

option.compile.deprecation=on

#将这个打开的时候,才认SpringMVC中的注解

option.compile.debug=true

option.compile.optimize=on

option.compile.target=1.7

#通过下面的方式实现打印信息

option.compile.verbose=true

 

dir.compile=./build

#目录结构

#---------------------------------------------------------------

dir.release=./dist

app-tpl.name=app-tpl

 

------分隔线----------------------------
------分隔线----------------------------

最新技术推荐