ant 编译java文件

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

你可能感兴趣的:(java,ant,JUnit,Build,include,encoding)