ant打JAR、WAR包

來源:互聯網
上載者:User

1. ant安裝

上官網下載ANT:http://ant.apache.org/bindownload.cgi

解壓出來,添加系統變數ANT_HOME,並把ANT路徑加入系統變數Path中

在命令列中,來到當前項目的路徑(打包檔案build.xml在該目錄下)

在命令列中輸入ant,斷行符號就可以看到結果

2. ant打JAR包

<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorld" basedir="." default="main">
<property name="src.dir" value="src" /> <!-- 源JAVA檔案的路徑 -->
<property name="build.dir" value="build-lib" /> <!-- JAR包存放的路徑 -->
<property name="classes.dir" value="${build.dir}/classes" /> <!-- CLASS檔案存放的路徑 -->
<property name="main-class" value="com.Main" /> <!-- 可以啟動並執行JAVA類 -->

<!-- 清理產生CLASS檔案和JAR包的檔案夾 -->
<target name="clean">
<delete dir="${build.dir}" />
</target>

<!-- 程式用到的第三方JAR包 -->
<path id="lib_classpath">
<fileset dir="lib/">
<include name="*.jar" />
</fileset>
</path>

<!-- 將JAVA檔案編譯成CLASS檔案,並存放到指定目錄build-lib/classes中-->
<target name="compile">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}">
<classpath refid="lib_classpath" />
</javac>
</target>

<!-- 將目錄build-lib/classes中的CLASS檔案打成JAR包 -->
<target name="jar" depends="compile">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.dir}/lib" />
<copy file="lib/jdom.jar" todir="${build.dir}/lib"/> <!-- 將第三方JAR包拷相應的目錄 -->
<jar destfile="${build.dir}/common-0.0.1.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}" />
<attribute name="Class-Path" value=". lib/jdom.jar"/><!-- 設定第三方JAR包的訪問路徑 -->
</manifest>
<!--<zipfileset src="E:\eastcom_workspace\Jar\lib\jdom.jar"/> 把第三方JAR包打進JAR包裡面,運行JAR包時會用到 -->
</jar>
</target>

<!-- 運行JAR包-->
<target name="run" depends="jar">
<java jar="${build.dir}/common-0.0.1.jar" fork="true">
</java>
</target>

<!-- 把產生的CLASS檔案刪除 -->
<target name="clean-build">
<delete dir="${classes.dir}" />
</target>

<target name="main" depends="clean, run, clean-build" />

</project>

Apache Ant 的詳細介紹:請點這裡
Apache Ant 的:請點這裡

如何在 Linux 伺服器上安裝 apache ant?

Apache Ant 的詳細介紹下載見

Android 編譯工具 Ant

 

更多精彩內容請看下一頁:

  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.