首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

Ant第一炮-Ant运作Java项目

2012-12-15 
Ant第一炮--Ant运行Java项目今天遇到了Ant运行Java项目的问题,网上是各种各样哈~还是自己总结一下下吧!Ant

Ant第一炮--Ant运行Java项目

今天遇到了Ant运行Java项目的问题,网上是各种各样哈~还是自己总结一下下吧!

Ant是什么就不多说了~自动都构建和部署工具嘛~

要运行Java项目基本步骤是先编译再运行,所以说需要两个部分,编译和运行,但在编译前也需要进行初始化吧~所以初始化先

初始化

?

<?xml version="1.0" encoding="utf-8"?><!-- 这个是必备的抬头 --><project name="DMS_IQE_BVT_Auto" basedir="." default="run"><!-- 项目属性 name 基本目录 和默认target --><!-- 配置基本属性 --><property name="src.dir" location="src" /><!-- 源码路径 --><property name="lib.dir" location="libs" /><!-- 引用包路径 --><property name="build.dir" location="bin" /><!-- build路径 --><property name="build.classes" location="${build.dir}/classes" /><!-- 编译后class文件路径 --><property name="test.debug" value="on"/> <!-- 是否debug --><!-- 配置运行时classpath 即 运行时需要的文件环境--><path id="classpath"><pathelement path="${build.classes}" /><fileset dir="${lib.dir}"><include name="**/*.jar" /></fileset></path>


以上是基本的参数属性的初始化,还需要对项目构建以前的清理和目录的建立哈~~~so

?

<target name="init" depends="cleanup" description="初始化">          <mkdir dir="${build.dir}"/>            <mkdir dir="${build.classes}"/></target>         <target name="cleanup" description="清理。。。">          <delete dir="${build.dir}"/>   </target>

?

然后就是编译啦~~这个简单

编译

?

<target name="compile" depends="init" description="编译程序"><!-- 编译src与test --><javac srcdir="${src.dir}" destdir="${build.classes}" includeAntRuntime="false" debug="${test.debug}" classpathref="classpath" encoding="UTF-8" debuglevel="source,lines,vars"><include name="**/*.java" /></javac></target>

?

打包要写么??还是以后再写一个吧,今天重点不在这~~

?

运行

?

<target name="run" depends="compile"> <property name="arg1" value="00" /><!-- 测试参数 -->  <property name="arg1" value="1" /><java fork="true" classname="com.test.MainClass"><!--运行命令-->     <arg value="${arg1}"/><!-- 参数 -->    <arg value="${arg2}"/>    <arg value="${arg3}"/>    <classpath path="${lib.dir}/package.jar"/><!-- Main函数所在位置 可以是${build.classes} -->    <classpath refid="classpath" /><!-- 资源classes -->   </java></target> 

主要是如果是框架开发,main函数路口在一个.jar包里需要指定MainClass和这个包的路径,自己写的main函数则可以给出编译后的classpath路径~

哈哈~先就这些吧~



?

热点排行