产品打包工具的制作,ant,编译源码,打jar包,打tag,打war包,备份release版本等
1、? 在進行打包工具的制作前,需要準(zhǔn)備的軟件有:
svnant-1.3.1 | 作用是讓ant和svn相關(guān)聯(lián) |
apache-ant-1.9.7 | 需要設(shè)置ant_home,path,我的配置是: ANT_HOME = D:\kaipu\cms4all\app-tpl-pack\apache-ant-1.9.7 Path = %ANT_HOME%\bin |
2、準(zhǔn)備好上面的操作之后,找個英文的目錄,比如:D:\kaipu\cms4all\app-tpl-pack,在目錄下創(chuàng)建兩個文件build.xml和build.properties,并把上面的svnant-1.3.1和apache-ant-1.9.7同樣放到相同目錄下,最后的目錄如下:
3、編寫build.xml文件
<?xml version="1.0" encoding="UTF-8"?> <!--default="dist"表示當(dāng)只執(zhí)行ant的時候,默認(rèn)執(zhí)行下面的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相關(guān)聯(lián),需要配置一個svnant,下面表示相關(guān)的內(nèi)容依賴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 ,新的設(shè)置SVN屬性方式--> ???????? <!-- 通過JAVAHL模式(即設(shè)置為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}" failοnerrοr="false" /> ? ???????? <!-- 導(dǎo)出源代碼,導(dǎo)出的過程中是從svn上checkout下來的,執(zhí)行的命令是: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版本創(chuàng)建tag,在svn上打上標(biāo)記--> ???????? <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,編譯,對應(yīng)java中的javac命令,其中srcdir定義源文件路徑? destdir定義編譯文件路徑 ?????????????????? includeantruntime作用是指定編譯任務(wù)是否包含ant的classpath,可有可無,不影響編譯,但不寫可能會出現(xiàn)警告,為了眼不見心不煩,加上吧 ?????????????????? --> ?????????????????? <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-1.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,編譯,對應(yīng)java中的javac命令,其中srcdir定義源文件路徑? destdir定義編譯文件路徑 ?????????????????? includeantruntime作用是指定編譯任務(wù)是否包含ant的classpath,可有可無,不影響編譯,但不寫可能會出現(xiàn)警告,為了眼不見心不煩,加上吧 ?????????????????? --> ?????????????????? <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-1.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> ???????? ???????? <!-- 需要參數(shù)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> ???????? ???????? <!-- 發(fā)布相關(guān)工程及依賴工具包,通過ant dist命令,可以一次性執(zhí)行清除、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的相關(guān)屬性 svn.user=這里填寫svn的用戶名 svn.pass=這里填寫svn的用戶名和密碼 svnant.dir=D:/kaipu/cms4all/app-tpl-pack/svnant-1.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-7.0.32/webapps/alfresco/WEB-INF/lib tomcat.lib.dir=./tomcatlib ? #svn服務(wù)器上的相關(guān)代碼位置 trunk.url=這里放svn上trunk版本的url地址 tags.url=這里放svn上tag版本的url地址 branches.url=這里放branches版本的url地址 release.url=這里放置release版本的url地址 #相關(guān)工程的信息 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-1.0-SNAPSHOT.jar tpl.jar.app-tpl-impl=app-tpl-impl-1.0-SNAPSHOT.jar tpl.war.app-tpl-webapp=app-tpl-webapp.war ? #本地編譯及發(fā)布的目錄結(jié)構(gòu) 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-8 option.compile.deprecation=on #將這個打開的時候,才認(rèn)SpringMVC中的注解 option.compile.debug=true option.compile.optimize=on option.compile.target=1.7 #通過下面的方式實現(xiàn)打印信息 option.compile.verbose=true ? dir.compile=./build #目錄結(jié)構(gòu) #--------------------------------------------------------------- dir.release=./dist app-tpl.name=app-tpl |
?
總結(jié)
以上是生活随笔為你收集整理的产品打包工具的制作,ant,编译源码,打jar包,打tag,打war包,备份release版本等的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 沈阳华晨宝马涂装和总装哪个好
- 下一篇: Java中把JSON和List结果集互转