Ant入门

java-only

md build\classes
javac
    -sourcepath src
    -d build\classes
    src\oata\HelloWorld.java
echo Main-Class: oata.HelloWorld>mf
md build\jar
jar cfm
    build\jar\HelloWorld.jar
    mf
    -C build\classes
    .
java -jar build\jar\HelloWorld.jar

=======================================
Ant
<mkdir dir="build/classes"/>
<javac
    srcdir="src"
    destdir="build/classes"/>
<!-- automatically detected -->
<!-- obsolete; done via manifest tag -->
<mkdir dir="build/jar"/>
<jar
    destfile="build/jar/HelloWorld.jar"

    basedir="build/classes">
    <manifest>
        <attribute name="Main-Class" value="oata.HelloWorld"/>
    </manifest>
</jar>
<java jar="build/jar/HelloWorld.jar" fork="true"/>
 
Example:
<?xml version="1.0" encoding="gb2312"?>  
<project default="dist">

	<property name="src.dir" value="./src"/>
	<property name="dest.dir" value="./build"/>
	
	<target name="clean">
		<echo message="delete file" />
		<delete dir="${dest.dir}"/>
	</target>
	
	<target name="prepare" depends="clean">
		<echo message="make file" />
		<mkdir dir="${dest.dir}"/>
	</target>
	
	<target name="compile" depends="prepare">
		<javac srcdir="${src.dir}" destdir="${dest.dir}">
		</javac>
	</target>
	
	<target name="dist" depends="compile">
		 <jar jarfile="${dest.dir}/A.jar"  basedir="${dest.dir}">  
		    <manifest> 
				<attribute name="Main-Class" value="temp.A"/> //生成后的META-INF/MANIFEST.MF中添加了Main-Class:temp.A
			</manifest> 
		</jar>
	</target>
</project>

你可能感兴趣的:(java,C++,c,xml,ant)