ant实际运用 - 导出jar包

java源码不说了,主要是build.xml

<?xml version="1.0" encoding="UTF-8" ?>
<project name="PingTool" default="run" basedir="." >      
<description>PingTools</description>  

<property name="src.dir" value="src" />   
<property name="dest.dir" value="classes" />   
<property name="run.classpath" value="${dest.dir}" /> 
<property name="jar.file" value="pingtools.jar" />	
<property name="main.class" value="MainFrame" />
  
<path id="compile.classpath">             
    <fileset dir="lib">                     
        <include name="*.jar" /> 
    </fileset> 
</path>
  
<target name="init">      
    <mkdir dir="${dest.dir}" />   
</target>  
  
<target name="compile" depends="init">   
    <javac srcdir="${src.dir}" destdir="${dest.dir}" encoding="UTF-8"  includeantruntime="false">  
        <classpath refid="compile.classpath" />
    </javac>  
</target>  

<target name="jar" depends="compile">
	<jar basedir="${dest.dir}" destfile="${jar.file}">
		<manifest>
			<attribute name="Main-Class" value="${main.class}" />
			<attribute name="Class-Path" value="" />
		</manifest>
		<zipfileset src="lib/jxl-2.6.3.jar" excludes="META-INF/*" />   <!-- 最关键的一点,把第三方jar包放到生成的jar中 -->
	</jar>
</target>
  
<target name="run" depends="jar"> 
    <java jar="${jar.file}"  fork="true" />
</target>  
  
<target name="clean">      
    <delete dir="${dest.dir}"/>
    <delete file="${jar.file}"/> 
</target>  
  
<target name="rerun" depends="clean"> 
    <ant target="run" />  
</target>  
  
</project>  
 

你可能感兴趣的:(xml,ant)