posts - 32,comments - 8,trackbacks - 0
1.接上文,在javademo下面新建文件 build.xml
<project>

    
<target name="clean">
        
<delete dir="build"/>
    
</target>

    
<target name="compile">
        
<mkdir dir="build/classes"/>
        
<javac srcdir="src" destdir="build/classes"/>
    
</target>

    
<target name="jar">
        
<mkdir dir="build/jar"/>
        
<jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
            
<manifest>
                
<attribute name="Main-Class" value="oata.HelloWorld"/>
            
</manifest>
        
</jar>
    
</target>

    
<target name="run">
        
<java jar="build/jar/HelloWorld.jar" fork="true"/>
    
</target>

</project>

2.运行:
ant compile
ant jar
ant run
看到结果

注意:要在系统环境里面设置PATH到ant的bin目录

3.更加简便的打包:修改build.xml,为:
<project name="HelloWorld" basedir="." default="main">

    
<property name="src.dir"     value="src"/>

    
<property name="build.dir"   value="build"/>
    
<property name="classes.dir" value="${build.dir}/classes"/>
    
<property name="jar.dir"     value="${build.dir}/jar"/>

    
<property name="main-class"  value="oata.HelloWorld"/>



    
<target name="clean">
        
<delete dir="${build.dir}"/>
    
</target>

    
<target name="compile">
        
<mkdir dir="${classes.dir}"/>
        
<javac srcdir="${src.dir}" destdir="${classes.dir}"/>
    
</target>

    
<target name="jar" depends="compile">
        
<mkdir dir="${jar.dir}"/>
        
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
            
<manifest>
                
<attribute name="Main-Class" value="${main-class}"/>
            
</manifest>
        
</jar>
    
</target>

    
<target name="run" depends="jar">
        
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
    
</target>

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

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

</project>
posted on 2008-12-04 11:50 张辰 阅读(393) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: