Ant 2.2.0 官方HelloWorld

本文介绍如何使用Apache ANT构建工具结合Ivy依赖管理器来组织和管理Java项目的构建过程。通过示例展示了如何配置build.xml文件来解决项目依赖,并运行项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值