- 浏览: 135997 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
zzjmates:
6楼说的最合理,具有建设性,合理性,稳定性,充满创新。
分布式集群系统下的高可用session解决方案 -
c497211969:
5楼正解。
分布式集群系统下的高可用session解决方案 -
liusp_eye:
redis的主从切换,可以采用Sentinel
分布式集群系统下的高可用session解决方案 -
抛出一枚硬币:
怎么没有下文了,楼主不是要未完待续?
分布式集群系统下的高可用session解决方案 -
yayoho:
或代码实现
分布式集群系统下的高可用session解决方案
Apache Ant™
Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications. Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications. Ant can also be used effectively to build non Java applications, for instance C or C++ applications. More generally, Ant can be used to pilot any type of process which can be described in terms of targets and tasks.
The latest version Ant1.8.2.
1. Ant安装(Windows)
- 下载ant最新版本并解压到文件目录
- 设置ANT_HOME环境变量
- JAVA_HOME目录
- 添加%ANT_HOME%\bin 到path
- 检查是否设置成功:ant -version
2. Ant构建文件(build.xml)
Build.xml由xml编写, ant构建文件对大小写敏感
3. 运行ant
ant命令:
ant [options] [target [target2 [target3] ...]]
Options:
-help, -h print this message
-projecthelp, -p print project help information
-version print the version information and exit
-diagnostics print information that might be helpful to
diagnose or report problems.
-quiet, -q be extra quiet
-verbose, -v be extra verbose
-debug, -d print debugging information
-emacs, -e produce logging information without adornments
-lib <path> specifies a path to search for jars and classes
-logfile <file> use given file for log
-l <file> ''
-logger <classname> the class which is to perform logging
-listener <classname> add an instance of class as a project listener
-noinput do not allow interactive input
-buildfile <file> use given buildfile
-file <file> ''
-f <file> ''
-D<property>=<value> use value for given property
-keep-going, -k execute all targets that do not depend
on failed target(s)
-propertyfile <name> load all properties from file with -D
properties taking precedence
-inputhandler <class> the class which will handle input requests
-find <file> (s)earch for buildfile towards the root of
-s <file> the filesystem and use it
-nice number A niceness value for the main thread:
1 (lowest) to 10 (highest); 5 is the default
-nouserlib Run ant without using the jar files from ${user.home}/.ant/lib
-noclasspath Run ant without using CLASSPATH
-autoproxy Java 1.5+ : use the OS proxies
-main <class> override Ant's normal entry point
Examples
ant
Ant将打开默认的构建文件,并执行默认的目标compile. 默认情况下,ant命令会在当前目录下寻找build.xml。
ant –buildfile test.xml
runs Ant using the test.xml file in the current directory, on the default target.
ant -buildfile test.xml dist
runs Ant using the test.xml file in the current directory, on the target called dist.
ant -buildfile test.xml -Dbuild=build/classes dist
runs Ant using the test.xml file in the current directory, on the target called dist, setting the build property to the value build/classes.
ant -lib /home/ant/extras
runs Ant picking up additional task and support jars from the /home/ant/extras location
ant -lib one.jar;another.jar
ant -lib one.jar -lib another.jar
adds two jars to Ants classpath.
4. Using Apache Ant
Structure of Buildfile
Task1 |
Task2 |
Property |
Path |
Taskn |
taskref |
Projects
A project has three attributes:
Attribute |
Description |
Required |
name |
the name of the project. |
No |
default |
the default target to use when no target is supplied. |
No; however, since Ant 1.6.0, every project includes an implicit target that contains any and all top-level tasks and/or types. This target will always be executed as part of the project's initialization, even when Ant is run with the -projecthelp option. |
basedir |
the base directory from which all path calculations are done. This attribute might be overridden by setting the "basedir" property beforehand. When this is done, it must be omitted in the project tag. If neither the attribute nor the property have been set, the parent directory of the buildfile will be used. |
e.g:
<project name="CopsTestComp" default="show property" basedir=”.”>
Targets
A target can depend on other targets. You might have a target for compiling, for example, and a target for creating a distributable. You can only build a distributable when you have compiled first, so the distribute target depends on the compile target. Ant resolves these dependencies.
For example:
<target name="jar" depends="clean,build">
……
</target>
Tasks
A task is a piece of code that can be executed.
<target name="build">
<mkdir dir="${path.build}" /> //task1
<javac classpath="${path.build}" debug="true" srcdir="src" destdir="${path.build}"> //task2
<include name="**/*.java" />
<classpath refid= "compile.classpath "/>
</javac>
</target>
Properties
Properties are an important way to customize a build process or to just provide shortcuts for strings that are used repeatedly inside a build file.
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
Use of external tasks
Ant supports a plugin mechanism for using third party tasks. For using them you have to do two steps:
- place their implementation somewhere where Ant can find them
- declare them.
Don't add anything to the CLASSPATH environment variable - this is often the reason for very obscure errors. Use Ant's own mechanisms for adding libraries:
-
via command line argument
-lib
-
adding to
${user.home}/.ant/lib
-
adding to
${ant.home}/lib
For the declaration there are several ways:
- declare a single task per using instruction using
<taskdef name="jag_connect" classname="com.sybase.jaguar.management.jagtool.ant.ConnectTask" />
-
declare a bundle of tasks using a properties-file holding these taskname-ImplementationClass-pairs and
<taskdef>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" /> <for ... />
-
declare a bundle of tasks using a xml-file holding these taskname-ImplementationClass-pairs and
<taskdef>
<taskdef resource="net/sf/antcontrib/antlib.xml" /> <for ... />
-
declare a bundle of tasks using a xml-file named antlib.xml, XML-namespace and
antlib:
protocoll handler<project xmlns:ac="antlib:net.sf.antconrib"/> <ac:for ... />
Example Buildfile
<?xml version="1.0"?>
<project name="Test" default="show property" basedir=”.”>
<property name="jar.file" value="${ant.project.name}.jar" />
<property name="entity.name" value="Package:${ant.project.name}" />
<property name="list.type" value="Package" />
<property name="path.build" value="${basedir}/bin" />
<property name="path.jar" value="D:/jar/jar_hksg/" />
<property name="webs.jar" value="D:/jar/jar_hksg/" />
<!-- EAServer properties -->
<property name="jaguar.host" value="192.168.0.11" />
<property name="jaguar.port" value="9091" />
<property name="jaguar.user" value="addddd" />
<property name="jaguar.password" value="123456" />
<!-- import EAServer task -->
<taskdef name="jag_connect" classname="com.sybase.jaguar.management.jagtool.ant.ConnectTask" />
<taskdef name="jag_deploy" classname="com.sybase.jaguar.management.jagtool.ant.DeployTask" />
<taskdef name="jag_delete" classname="com.sybase.jaguar.management.jagtool.ant.DeleteTask" />
<taskdef name="jag_refresh" classname="com.sybase.jaguar.management.jagtool.ant.RefreshTask" />
<taskdef name="jag_restart" classname="com.sybase.jaguar.management.jagtool.ant.RestartTask" />
<taskdef name="jag_shutdown" classname="com.sybase.jaguar.management.jagtool.ant.ShutdownTask" />
<taskdef name="jag_list" classname="com.sybase.jaguar.management.jagtool.ant.ListTask" />
<target name="jar" depends="clean,build">
<delete file="${jar.file}"/>
<jar destfile="${jar.file}">
<fileset dir="${path.build}" includes="**/*.*" />
<fileset dir="${basedir}" includes="META-INF/**" />
</jar>
</target>
<target name="connect">
<jag_connect host="${jaguar.host}" port="${jaguar.port}" user="${jaguar.user}" password="${jaguar.password}" />
</target>
<target name="restart" depends="connect">
<jag_restart />
<waitfor checkevery="1" checkeveryunit="second">
<socket server="${jaguar.host}" port="${jaguar.port}" />
</waitfor>
</target>
<target name="shutdown" depends="connect">
<jag_shutdown />
</target>
<target name="deploy" depends="jar,connect">
<jag_deploy type="ejbjar" install="true" strategy="full" file="${basedir}/${jar.file}" verbose="true" />
<jag_refresh entity="${entity.name}" />
</target>
<target name="undeploy" depends="connect">
<jag_delete entity="${entity.name}" />
</target>
<target name="list" depends="connect">
<jag_list type="${list.type}" />
</target>
<target name="refresh" depends="connect">
<jag_refresh entity="${entity.name}" />
</target>
<target name="clean">
<delete includeEmptyDirs="true">
<fileset dir="${path.build}" />
</delete>
</target>
<target name="build">
<mkdir dir="${path.build}" />
<javac classpath="${path.build}" debug="true" srcdir="src" destdir="${path.build}">
<include name="**/*.java" />
<classpath refid= "compile.classpath "/>
</javac>
</target>
<path id= "compile.classpath ">
<pathelement path = "${path.jar}easj2ee.jar"/>
<pathelement path = "${path.jar}log4j-1.2.15.jar "/>
<pathelement path = "${path.jar}easserver.jar"/>
<pathelement path = "${path.jar}easclient.jar"/>
<pathelement path = "${path.jar}hksps.jar"/>
<pathelement path = "${path.jar}common.jar"/>
<pathelement path = "${path.jar}mbclnt50.jar"/>
</path>
<target name="show property">
<echo message="Host:${jaguar.host}"/>
<echo message="Port:${jaguar.port}"/>
</target>
</project>
The structure of the build.xml:
Stucture of build.xml
参考文档
Apache Ant™ 1.8.2 Manual(http://ant.apache.org/manual/index.html)
发表评论
-
wp app crawl
2014-10-21 18:08 0package com.iemis.wdc; imp ... -
dddd
2014-09-30 16:16 0package com.iemis.wdc; impo ... -
proxy
2014-09-01 18:15 0package test; import java.i ... -
crawller of dex
2014-08-21 16:59 0package com.iemis.wdc; ... -
Java运行内存
2014-05-13 11:19 0Java运行内存学习与研究 java中的内存结构: ... -
Spring加载XML机制(mark link)
2014-04-03 11:33 661Spring加载XML机制 http://www.c ... -
JPA ID生成策略(转)
2014-03-03 16:19 35230JPA ID生成策略 @Table Table用来定义e ... -
j2ee study
2013-12-05 18:33 0spring study 3 -
spring in action
2013-12-04 19:46 0spring study <?xml versio ... -
pc study
2013-11-15 00:19 0test -
java study
2013-10-11 17:29 0java study -
get IP
2013-10-11 00:08 0package com.iemis.datatransfe ... -
thumbupdate
2013-10-09 17:39 0package com.iemis.proc; imp ... -
dddd
2013-10-02 17:38 0try { doc = Jsoup.connec ... -
java jvm学习笔记
2013-09-23 10:58 0趁着项目的空窗期,拜读以下java 虚拟机一书, 现将相关 ... -
ant build 项目实例
2013-04-22 16:29 842<project name="MyWebA ... -
Eclipse jvm运行时设置代理
2012-08-14 15:54 6503Eclipse 编写应用程序设置代理 对于一般的We ... -
Get Tree Path
2012-02-22 17:44 1010public class Test { /** ...
相关推荐
ant学习笔记之(ant执行命令的详细参数和Ant自带的系统属性)
Ant学习笔记
ant 学习笔记 ,自己的一些学的时候的一个例子
Ant学习笔记Ant学习笔记Ant学习笔记
NULL 博文链接:https://worktianqi.iteye.com/blog/2162932
博文链接:https://jimjiang.iteye.com/blog/123820
ant 笔记 来源网络
关于Ant学习的一点点小结,整理成档了,文档中已经包含了几个简单的build.xml实例,也有注释,简单明了、通俗易懂
ant个人学习笔记和简单示例,主要包括各种命令,以及简单的示例
Java/JavaEE 学习笔记 作者在杰普学习时的学习笔记,是J2ee初学者必备手册,是大家学习J2EE开发的很好的参考笔记。 Java/JavaEE 学习笔记 内容...ant学习笔记...................387 Web Service学习笔记.....388
内容目录 .......................1 Java/JavaEE.....1 2008年11月1日...............1 Unix 学习笔记7 一、Unix前言............7 ...ant学习笔记...................387 Web Service学习笔记.....388
十分有用的ant资料,由此可以快速入门.
1 20个Java基础Tips 2 abstract,static,final修饰符 3 ChinaUnix.net Java精华贴 4 ANT学习笔记 5 极度性能调整 <br> FAQs 1 关于ConnectionManager中的代码 2 关于...
NULL 博文链接:https://shawnfree.iteye.com/blog/346466
Ant Design Pro 4.x学习笔记(一)基础 简介 自己学习的一点心得,希望有不足的地方,轻喷。 Ant Design Pro 是ant的一个项目,是一个企业级中后台前端/设计解决方案,与Ant Design 一脉同源。学习Ant Design Pro ...
Java JDK 5.0学习笔记 1至6章及附录A和附录B 包含java特性、java学习方法、网络资源汇总、jdk下载和安装、path与CLASSPATH的设置、java基本语法、关于对象的认识、数组、字符串(String类))、Ant简介、JUnit简介。 ...