ant 編譯java檔案

來源:互聯網
上載者:User

1、projecthome.cmd

set PROJECT_HOME=

 

2、cpappend.cmd

set CLASSPATH=%LIB_HOME%/%1;%CLASSPATH%

 

3、build.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE project [<!ENTITY buildfile SYSTEM "file:./build-user.xml">]>
<!-- WARNING: Eclipse autogenerated file.
              Any modifications will be overwritten.
              Please edit build-user.xml instead.
-->
<project default="final" name="***系統">
<!--定義指向目錄的快捷符號-->
    <property environment="env"/>
    <property name="PRJ.SRC" value="${env.PROJECT_HOME}/src"/>
    <property name="PRJ.EXTSRC" value="${env.PROJECT_HOME}/src from projecting/"/>
    <property name="PRJ.TEMP" value="${env.PROJECT_HOME}/temp"/>
    <property name="PRJ.LIB" value="${env.PROJECT_HOME}/lib"/>
    <property name="PRJ.PERSISTENT" value="${env.PROJECT_HOME}/PERSISTENT"/>

<!--初始化TEMP目錄,以便儲存編譯後的檔案 -->
    <target name="init">
 <echo message="Initalizing..."/>
 <delete dir="${PRJ.TEMP}"/>
 <mkdir dir="${PRJ.TEMP}"/>
 <delete >
  <fileset dir="${PRJ.PERSISTENT}">
   <include name="**/*.*" />
  </fileset>
 </delete>
  </target>
   
<!--編譯PRJ.SRC檔案夾下的Java檔案,產生class檔案,存放在臨時檔案夾下-->
    <target depends="init" name="build">
        <echo message="Building... "/>
        <javac  srcdir="${PRJ.SRC}/"
          destdir="${PRJ.TEMP}/"
          debug="true"
          encoding="UTF-8">
            <classpath >
             <fileset dir="${PRJ.LIB}">
              <include name="**/*.jar" />
             </fileset>
            </classpath>
        </javac>
    </target>

   <!-- 測試 --> 
        <target name="test" depends="build" description="run junit test"> 
            <echo>下面開始測試${PRJ.TEMP}</echo> 
            <fail if="tests.failed"> 
              
            </fail> 
        </target>

<!--將臨時檔案夾下的檔案打包,存放在PRJ.PERSISTENT-->
 <target name="pack" depends="build,resource" >
     <jar compress="false" destfile="${PRJ.PERSISTENT}/persistent.jar">
       <fileset dir="${PRJ.TEMP}">
         <include name="**/*.*"/>
       </fileset>
     </jar>
  </target>
  
<!--執行結束後刪除臨時檔案夾-->
    <target name="final" depends="pack">
   <echo message="Deleting..."/>
   <delete dir="${PRJ.TEMP}"/>
    </target>
   
<!--把原檔案中的一些資源檔複製到臨時檔案夾中,以便打包-->
  <target name="resource" depends="init">
    <copy todir="${PRJ.TEMP}">
      <fileset dir="${PRJ.SRC}">
        <include name="**/*.jpe"/>
        <include name="**/*.jpeg"/>
        <include name="**/*.rmf"/>
        <include name="**/*.wav"/>
        <include name="**/*.mid"/>
        <include name="**/*.midi"/>
        <include name="**/*.au"/>
        <include name="**/*.gif"/>
        <include name="**/*.png"/>
        <include name="**/*.jpg"/>
        <include name="**/*.aiff"/>
        <include name="**/*.properties"/>
  <include name="**/*.xml"/>
  <include name="**/*.swf"/>
      </fileset>
    </copy>
  </target>

</project>

 

4、build.cmd

 

@echo off

rem 擷取當前路徑
copy   projecthome.cmd   temp.cmd>nul  
cd..
cd >>builder/temp.cmd
cd builder 
call   temp.cmd  
del   temp.cmd    
echo 當前路徑為 %PROJECT_HOME%

rem set JAVA_HOME=%PROJECT_HOME%/java/jdk1.5.0_02
rem set JDK_HOME=%PROJECT_HOME%/java/jdk1.5.0_02
rem set JRE_HOME=%PROJECT_HOME%/java/jre1.5.0_02
set ANT_HOME=%PROJECT_HOME%/ant
set LIB_HOME=%PROJECT_HOME%/lib
set CLASSPATH=%JDK_HOME%/lib/tools.jar
set path=%ANT_HOME%/bin;%path%

echo adding all jar in lib directory
for %%i in (../lib/*.jar) do call cpappend %%i

@echo on
ant

相關文章

聯繫我們

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