`

Ant 2.2.0 官方HelloWorld

 
阅读更多

1【Java EE】【ANT专辑 一】ANT在Web项目中的应用--工具介绍

+官方HelloWorld

  1.build.xml

 

 

<!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.    
-->
<project name="hello-ivy" default="run" xmlns:ivy="antlib:org.apache.ivy.ant">
    <!-- some variables used -->
    <property name="lib.dir" value="lib" />
    <property name="build.dir" value="build" />
    <property name="src.dir" value="src" />
    
    <!-- paths used for compilation and run  -->
    <path id="lib.path.id">
        <fileset dir="${lib.dir}" />
	  </path>
    <path id="run.path.id">
    		<!--引用jar包路径-->
        <path refid="lib.path.id" />
        <!--引用二进制文件路径-->
        <path location="${build.dir}" />
    </path>
    
    <!-- ================================= 
          target: resolve              
         ================================= -->
    <target name="resolve" description="--> retreive dependencies with ivy">
        <ivy:retrieve/>
    </target>    
    
    <!-- ================================= 
          target: report              
         ================================= -->
    <target name="report" depends="resolve" description="--> generates a report of dependencies">
        <ivy:report todir="${build.dir}"/>
    </target>

    <!-- ================================= 
          target: run
         ================================= -->
    <target name="run" depends="resolve" description="--> compile and run the project">
        <!--创建文件夹-->
        <mkdir dir="${build.dir}" />
        <!--编译的只需要引用jar包,classpathref=lib.path.id 下的jar包-->
        <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="lib.path.id" />
    	  <property name="msg" value="hello ivy !"/>
        <!--跑java code , 这是时候引用的外部jar包是 class文件+ jar包-->
        <java classpathref="run.path.id" classname="example.Hello">
        	<arg value="-message"/>
        	<arg value="${msg}"/>
    	  </java>
    </target>

    <!-- ================================= 
          target: clean              
         ================================= -->
    <target name="clean" description="--> clean the project">
        <delete includeemptydirs="true">
        	<!-- fileSet 顾名思义就是file 集合。-->
            <fileset dir="${basedir}">
            	<exclude name="src/**" />
            	<exclude name="build.xml" />
              <exclude name="ivy.xml" />
        	</fileset>
    	</delete>
    </target>
	
    <!-- ================================= 
          target: clean-cache              
         ================================= -->
	<target name="clean-cache" description="--> clean the ivy cache">
		<ivy:cleancache />
	</target>
</project>
 

 

因为加了中文,所以用UE保存为UTF-8就不会报:Invalid byte 2 of 2-byte UTF-8 sequence.异常

2.ivy.xml

 

<ivy-module version="2.0">
    <info organisation="org.apache" module="hello-ivy"/>
    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.0"/>
        <dependency org="commons-cli" name="commons-cli" rev="1.0"/>
    </dependencies>
</ivy-module>
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics