ant的進階使用,ant命令詳解,ant打包,ant編譯後打包去掉jar檔案

來源:互聯網
上載者:User

標籤:ant   build.xml   ant打包   ant命令詳解   ant編譯java檔案   

在日常的項目開發中,我們可以經常性的需要打包測試,尤其是開發環境是windows,而實際環境則是linux。
這樣的話,很多程式員要一會打一個包,一會打一個包,這些包可能會很大,實際上只有代碼部分會變動,而jar包基本則不動。
當然很多人可能會說,自動化測試。很好的,我們今天要做的就是自動化測試的第一步。
這個時候我是可以使用ant來打包,去掉項目中的所有的jar檔案。然後在項目的tomcat啟動時到特定的地點去載入jar檔案。

這樣做,war包可能會只有幾M,什麼更小。具體如何動態載入jar檔案,我們在下一章講解,這一章,我們先來看ant打包的build.xml配置。

看原始碼:

<?xml version="1.0" encoding="UTF-8" ?><project name="nojar" default="deleteClasses" basedir="."><property name="classes" value="build/classes" /><property name="build" value="build" /><property name="lib" value="WebRoot/WEB-INF/lib" /><path id="compile.jar"><fileset dir="${lib}"><include name="*.jar" /></fileset></path><!-- 刪除build路徑--><target name="deleteBuild"><delete dir="build" /><copy todir="${classes}/com/herman/config"><fileset dir="${basedir}/src/com/herman/config"><include name="*" /></fileset></copy></target><!-- 建立build/classes路徑,並編譯class檔案到build/classes路徑下--><target name="compile" depends="deleteBuild"><mkdir dir="${classes}" /><javac srcdir="src" destdir="${classes}" includeantruntime="on" encoding="utf-8"><classpath refid="compile.jar" /></javac></target><!-- 打war包--><target name="war" depends="compile"><war warfile="${build}/nojar.war" webxml="WebRoot/WEB-INF/web.xml" encoding="utf-8">   <!-- 拷貝WebRoot下除了WEB-INF和META-INF的兩個檔案夾--><fileset dir="WebRoot" includes="**/*.jsp"></fileset><!--<fileset dir="WebRoot" includes="**/*.*" excludes="META-INF,WEB-INF"/>--><!-- 拷貝lib目錄下的jar包--><!--<lib dir="${lib}" />--><!-- 拷貝build/classes下的class檔案--><classes dir="${classes}" />        </war>    </target><!-- 刪除build/下的classes下的位元組碼檔案,減少war包的總大小--><target name="deleteClasses" depends="war"><!--<delete dir="${classes}"></delete>--></target></project>
是不是很簡單,好吧,如果你認為本文還可以,請關注我的個人部落格!

或者加入QQ群:135430763共同學習!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.