博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ant读书之使用ant进行java开发--第二章
阅读量:6841 次
发布时间:2019-06-26

本文共 5959 字,大约阅读时间需要 19 分钟。

hot3.png

几条总结:

一。在ant的构建文件中,根元素始终是:<project>

二。ant的概念模型:项目包含目标,目标包含任务,也就是把所有的目标放在目标中,即:所有的target,在project根标签下,且不要有其他东西在project根标签下。所有的执行过程,在targert标签中

三。在ant中,任何一个任务失败,会导致整个构建过程的终止

四。javac命令中依赖关系检查仅仅局限于在比对源文件与目标文件的日期上

我的代码:

HelloWorld.java//主类

package com.laolang.hello;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import com.laolang.stu.Student;public class HelloWorld {	public static void main(String[] args) {		BufferedReader br = new BufferedReader(new InputStreamReader(				System.in));		Student stu = null;		int id = 0;		String name = null;		int age = 0;		String sex = null;		try {			System.out.print("输入学号:");			id = Integer.parseInt(br.readLine());			System.out.print("输入姓名:");			name = br.readLine();			System.out.print("输入年龄:");			age = Integer.parseInt(br.readLine());			System.out.print("输入性别:");			sex = br.readLine();		} catch (NumberFormatException | IOException e) {			e.printStackTrace();		}		stu = new Student(id, name, age, sex);		System.out.println("student:");		System.out.println(stu);		System.out.println("Hello World!");		System.out.println("小代码!");	}}

Student.java//学生类

package com.laolang.stu;public class Student {	public Student() {		super();	}	public Student(int stuId, String stuName, int stuAge, String stuSex) {		super();		this.stuId = stuId;		this.stuName = stuName;		this.stuAge = stuAge;		this.stuSex = stuSex;	}	@Override	public String toString() {		return "Student [stuId=" + stuId + ", stuName=" + stuName				+ ", stuAge=" + stuAge + ", stuSex=" + stuSex				+ "]";	}	public int getStuId() {		return stuId;	}	public void setStuId(int stuId) {		this.stuId = stuId;	}	public String getStuName() {		return stuName;	}	public void setStuName(String stuName) {		this.stuName = stuName;	}	public int getStuAge() {		return stuAge;	}	public void setStuAge(int stuAge) {		this.stuAge = stuAge;	}	public String getStuSex() {		return stuSex;	}	public void setStuSex(String stuSex) {		this.stuSex = stuSex;	}	private int stuId;	private String stuName;	private int stuAge;	private String stuSex;}

build.xml

这是使用ant进行JAVA开发的第一个完整的例子

运行效果:

laolang@laolang:~/code/ant/book/two/first_build_35$ l总用量 8.0K4.0K -rw-rw-r-- 1 laolang laolang 1011 11月 21 21:54 build.xml4.0K drwxrwxr-x 3 laolang laolang 4.0K 11月 21 21:12 src/laolang@laolang:~/code/ant/book/two/first_build_35$ tree.├── build.xml└── src    └── com        └── laolang            ├── hello            │   └── HelloWorld.java            └── stu                └── Student.java5 directories, 3 fileslaolang@laolang:~/code/ant/book/two/first_build_35$ ant -projecthelp Buildfile: /home/laolang/code/ant/book/two/first_build_35/build.xml这是使用ant进行JAVA开发的第一个完整的例子Main targets: archive  打包 clean    清除中间文件 compile  编译 execute  运行 init     初始化Default target: archivelaolang@laolang:~/code/ant/book/two/first_build_35$ ant compileBuildfile: /home/laolang/code/ant/book/two/first_build_35/build.xmlinit:    [mkdir] Created dir: /home/laolang/code/ant/book/two/first_build_35/build/classes    [mkdir] Created dir: /home/laolang/code/ant/book/two/first_build_35/distcompile:    [javac] /home/laolang/code/ant/book/two/first_build_35/build.xml:14: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds    [javac] Compiling 2 source files to /home/laolang/code/ant/book/two/first_build_35/build/classesBUILD SUCCESSFULTotal time: 1 secondlaolang@laolang:~/code/ant/book/two/first_build_35$ ant execute Buildfile: /home/laolang/code/ant/book/two/first_build_35/build.xmlinit:compile:    [javac] /home/laolang/code/ant/book/two/first_build_35/build.xml:14: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable buildsexecute:     [echo] running1001tianya34nan     [java] 输入学号:输入姓名:输入年龄:输入性别:student:     [java] Student [stuId=1001, stuName=tianya, stuAge=34, stuSex=nan]     [java] Hello World!     [java] 小代码!BUILD SUCCESSFULTotal time: 7 secondslaolang@laolang:~/code/ant/book/two/first_build_35$ ant archive Buildfile: /home/laolang/code/ant/book/two/first_build_35/build.xmlinit:compile:    [javac] /home/laolang/code/ant/book/two/first_build_35/build.xml:14: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable buildsarchive:      [jar] Building jar: /home/laolang/code/ant/book/two/first_build_35/dist/project.jarBUILD SUCCESSFULTotal time: 0 secondslaolang@laolang:~/code/ant/book/two/first_build_35$ tree.├── build│   └── classes│       └── com│           └── laolang│               ├── hello│               │   └── HelloWorld.class│               └── stu│                   └── Student.class├── build.xml├── dist│   └── project.jar└── src    └── com        └── laolang            ├── hello            │   └── HelloWorld.java            └── stu                └── Student.java12 directories, 6 fileslaolang@laolang:~/code/ant/book/two/first_build_35$ ant cleanBuildfile: /home/laolang/code/ant/book/two/first_build_35/build.xmlinit:clean:   [delete] Deleting directory /home/laolang/code/ant/book/two/first_build_35/build   [delete] Deleting directory /home/laolang/code/ant/book/two/first_build_35/distBUILD SUCCESSFULTotal time: 0 secondslaolang@laolang:~/code/ant/book/two/first_build_35$ tree.├── build.xml└── src    └── com        └── laolang            ├── hello            │   └── HelloWorld.java            └── stu                └── Student.java5 directories, 3 fileslaolang@laolang:~/code/ant/book/two/first_build_35$ l总用量 8.0K4.0K -rw-rw-r-- 1 laolang laolang 1011 11月 21 21:54 build.xml4.0K drwxrwxr-x 3 laolang laolang 4.0K 11月 21 21:12 src/laolang@laolang:~/code/ant/book/two/first_build_35$

转载于:https://my.oschina.net/iamhere/blog/347344

你可能感兴趣的文章
nginx支持http 和https共存
查看>>
关于在使用iframe之后子页面中如何在父级弹窗的问题的具体实现
查看>>
win7 激活工具
查看>>
Spring中事务与aop的先后顺序问题
查看>>
我们应当使用安全的https通信
查看>>
linux下实现双网卡的绑定
查看>>
Project Server 2013新手入门 (十二)特定工作组
查看>>
日期—时间戳转换(PHP,Mysql)
查看>>
用Kiwi Syslog 搭建集中管理的日志服务器
查看>>
wiindows 2012R2+11gR2RAC(11204)安装grid报INS-20802错误
查看>>
Jquery Validate 取消校验
查看>>
JVM Crash
查看>>
执行Runtime.exec异常: error=12,Cannot allocate memory
查看>>
vi详解
查看>>
看我用ubuntu && virtualbox
查看>>
窗体之间传值的暴力方法
查看>>
光纤收发器常见故障解答
查看>>
python入门指引
查看>>
偷懒的后果,又栽在C语言的变量声明上
查看>>
LNMP+zabbix一键安装部署
查看>>