??xml version="1.0" encoding="utf-8" standalone="yes"?>
一.JAVA电子?/p>
优点Q书c量大,l常更新Q教育网下蝲速度快
不Q每天只能下??/p>
W一部分Q选择?br/>QUESTION NO: 1
1、public class Test {
public static void changeStr(String str){
str="welcome";
}
public static void main(String[] args) {
String str="1234";
changeStr(str);
System.out.println(str);
}
}
Please write the output result Q?/p>
QUESTION NO:2
1. public class Test {
2. static boolean foo(char c) {
3. System.out.print(c);
4. return true;
5. }
6. public static void main( String[] argv ) {
7. int i =0;
8. for ( foo('A'); foo('B')&&(i<2); foo('C')){
9. i++ ;
10. foo('D');
12. }
13. }
14. }
What is the result?
A. ABDCBDCB
B. ABCDABCD
C. Compilation fails.
D. An exception is thrown at runtime.
QUESTION NO: 3
1. class A {
2. protected int method1(int a, int b) { return 0; }
3. }
Which two are valid in a class that extends class A? (Choose two)
A. public int method1(int a, int b) { return 0; }
B. private int method1(int a, int b) { return 0; }
C. private int method1(int a, long b) { return 0; }
D. public short method1(int a, int b) { return 0; }
E. static protected int method1(int a, int b) { return 0; }
QUESTION NO: 4
1. public class Outer{
2. public void someOuterMethod() {
3. // Line 3
4. }
5. public class Inner{}
6. public static void main( String[]argv ) {
7. Outer o = new Outer();
8. // Line 8
9. }
10. }
Which instantiates an instance of Inner?
A. new Inner(); // At line 3
B. new Inner(); // At line 8
C. new o.Inner(); // At line 8
D. new Outer.Inner(); // At line 8//new Outer().new Inner()
QUESTION NO: 5
Which method is used by a servlet to place its session ID in a URL that is written to the servlet's response output stream?
A. The encodeURL method of the HttpServletRequest interface.
B. The encodeURL method of the HttpServletResponse interface.
C. The rewriteURL method of the HttpServletRequest interface.
D. The rewriteURL method of the HttpServletResponse interface.
QUESTION NO: 6
Which two are equivalent? (Choose two)
A. <%= YoshiBean.size%>
B. <%= YoshiBean.getSize()%>
C. <%= YoshiBean.getProperty("size")%>
D. <jsp:getProperty id="YoshiBean" param="size"/>
E. <jsp:getProperty name="YoshiBean" param="size"/>
F. <jsp:getProperty id="YoshiBean" property="size"/>
G. <jsp:getProperty name="YoshiBean" property="size"/>
QUESTION NO: 7
Which of the following statements regarding the lifecycle of a session bean are correct?
1. java.lang.IllegalStateException is thrown if SessionContext.getEJBObject() is invoked when a stateful session bean instance is passivated.
2. SessionContext.getRollbackOnly() does not throw an exception when a session bean with bean-managed transaction demarcation is activated.
3. An exception is not thrown when SessionContext.getUserTransaction() is called in the afterBegin method of a bean with container-managed transactions.
4. JNDI access to java:comp/env is permitted in all the SessionSynchronization methods of a stateful session bean with container-managed transaction demarcation.
5. Accessing resource managers in the SessionSynchronization.afterBegin method of a stateful session bean with bean-managed transaction does not throw an exception.
W二部分Q概念题
1Q?描述Struts体系l构Q对应各个部分的开发工作主要包括哪些?
2Q?XML包括哪些解释技术,区别是什么?
3Q?JSP有哪些内|对象和动作Q它们的作用分别是什么?
4、SQL问答?br/>SELECT * FROM TABLE
?br/>SELECT * FROM TABLE
WHERE NAME LIKE '%%' AND ADDR LIKE '%%'
AND (1_ADDR LIKE '%%' OR 2_ADDR LIKE '%%'
OR 3_ADDR LIKE '%%' OR 4_ADDR LIKE '%%' )
的检索结果ؓ何不同?
5、SQL问答?br/>表结构:
1?表名Qg_cardapply
字段(字段?cd/长度)Q?br/>g_applyno varchar 8Q?/甌单号Q关键字Q?br/>g_applydate bigint 8Q?/甌日期
g_state varchar 2Q?/甌状?br/>2?表名Qg_cardapplydetail
字段(字段?cd/长度)Q?br/>g_applyno varchar 8Q?/甌单号Q关键字Q?br/>g_name varchar 30Q?/甌人姓?br/>g_idcard varchar 18Q?/甌n份证?br/>g_state varchar 2Q?/甌状?br/>其中Q两个表的关联字Dؓ甌单号?br/>题目Q?br/>1?查询w䆾证号码ؓ440401430103082的申h?br/>2?查询同一个n份证L有两条以上记录的w䆾证号码及记录个数
3?n份证L?40401430103082的记录在两个表中的申L态均改ؓ07
4?删除g_cardapplydetail表中所有姓李的记录
在应用程序中d日志记录ȝ来说Z三个目的Q监视代码中变量的变化情况,周期性的记录到文件中供其他应用进行统计分析工作;跟踪代码q行时轨q,作ؓ日后审计的依据;担当集成开发环境中的调试器的作用,向文件或控制台打C码的调试信息?/p>
最普通的做法是在代码中嵌入许多的打印语句,q些打印语句可以输出到控制台或文件中Q比较好的做法就是构造一个日志操作类来封装此cL作,而不是让一pd的打印语句充斥了代码的主体?/p>
在强调可重用lg开发的今天Q除了自׃头到ּ发一个可重用的日志操作类外,Apache为我们提供了一个强有力的日志操作包-Log4j?/p>
Log4j是Apache的一个开放源代码目Q通过使用Log4jQ我们可以控制日志信息输送的目的地是控制台、文件、GUIlg、甚x套接口服务器、NT的事件记录器、UNIX Syslog守护q程{;我们也可以控制每一条日志的输出格式Q通过定义每一条日志信息的U别Q我们能够更加细致地控制日志的生成过E。最令h感兴的是Q这些可以通过一个配|文件来灉|地进行配|,而不需要修改应用的代码?/p>
此外Q通过Log4j其他语言接口Q您可以在C、C++?Net、PL/SQLE序中用Log4jQ其语法和用法与在JavaE序中一P使得多语a分布式系l得C个统一一致的日志lg模块。而且Q通过使用各种W三Ҏ展,您可以很方便地将Log4j集成到J2EE、JINI甚至是SNMP应用中?/p>
本文介绍的Log4j版本?.2.3。作者试N过一个简单的客户/服务器JavaE序例子Ҏ使用与不使用Log4j 1.2.3的差别,q详l讲解了在实践中最怋用Log4j的方法和步骤。在可重用组件开发的今天Q相信Log4j会l广大的设计开发h员带来方ѝ加入到Log4j的队伍来吧!
我们先来看一个简单的例子Q它是一个用Java实现的客?服务器网l程序。刚开始我们不使用Log4jQ而是使用了一pd的打印语句,然后我们用Log4j来实现它的日志功能。这P大家可以清楚地比较出前后两个代码的差别?/p>
2.1.1. 客户E序
package log4j ;
import java.io.* ;
import java.net.* ;
/**
*
* <p> Client Without Log4j </p>
* <p> Description: a sample with log4j</p>
* @version 1.0
*/
public class ClientWithoutLog4j {
/**
*
* @param args
*/
public static void main ( String args [] ) {
String welcome = null;
String response = null;
BufferedReader reader = null;
PrintWriter writer = null;
InputStream in = null;
OutputStream out = null;
Socket client = null;
try {
client = new Socket ( "localhost", 8001 ) ;
System.out.println ( "info: Client socket: " + client ) ;
in = client.getInputStream () ;
out = client.getOutputStream () ;
} catch ( IOException e ) {
System.out.println ( "error: IOException : " + e ) ;
System.exit ( 0 ) ;
}
try{
reader = new BufferedReader( new InputStreamReader ( in ) ) ;
writer = new PrintWriter ( new OutputStreamWriter ( out ), true ) ;
welcome = reader.readLine () ;
System.out.println ( "debug: Server says: '" + welcome + "'" ) ;
System.out.println ( "debug: HELLO" ) ;
writer.println ( "HELLO" ) ;
response = reader.readLine () ;
System.out.println ( "debug: Server responds: '" + response + "'") ;
System.out.println ( "debug: HELP" ) ;
writer.println ( "HELP" ) ;
response = reader.readLine () ;
System.out.println ( "debug: Server responds: '" + response + "'" ) ;
System.out.println ( "debug: QUIT" ) ;
writer.println ( "QUIT" ) ;
} catch ( IOException e ) {
System.out.println ( "warn: IOException in client.in.readln()" ) ;
System.out.println ( e ) ;
}
try{
Thread.sleep ( 2000 ) ;
} catch ( Exception ignored ) {}
}
}
2.1.2. 服务器程?/strong>
package log4j ;
import java.util.* ;
import java.io.* ;
import java.net.* ;
/**
*
* <p> Server Without Log4j </p>
* <p> Description: a sample with log4j</p>
* @version 1.0
*/
public class ServerWithoutLog4j {
final static int SERVER_PORT = 8001 ; // this server's port
/**
*
* @param args
*/
public static void main ( String args [] ) {
String clientRequest = null;
BufferedReader reader = null;
PrintWriter writer = null;
ServerSocket server = null;
Socket socket = null;
InputStream in = null;
OutputStream out = null;
try {
server = new ServerSocket ( SERVER_PORT ) ;
System.out.println ( "info: ServerSocket before accept: " + server ) ;
System.out.println ( "info: Java server without log4j, on-line!" ) ;
// wait for client's connection
socket = server.accept () ;
System.out.println ( "info: ServerSocket after accept: " + server ) ;
in = socket.getInputStream () ;
out = socket.getOutputStream () ;
} catch ( IOException e ) {
System.out.println( "error: Server constructor IOException: " + e ) ;
System.exit ( 0 ) ;
}
reader = new BufferedReader ( new InputStreamReader ( in ) ) ;
writer = new PrintWriter ( new OutputStreamWriter ( out ) , true ) ;
// send welcome string to client
writer.println ( "Java server without log4j, " + new Date () ) ;
while ( true ) {
try {
// read from client
clientRequest = reader.readLine () ;
System.out.println ( "debug: Client says: " + clientRequest ) ;
if ( clientRequest.startsWith ( "HELP" ) ) {
System.out.println ( "debug: OK!" ) ;
writer.println ( "Vocabulary: HELP QUIT" ) ;
}
else {
if ( clientRequest.startsWith ( "QUIT" ) ) {
System.out.println ( "debug: OK!" ) ;
System.exit ( 0 ) ;
}
else{
System.out.println ( "warn: Command '" +
clientRequest + "' not understood." ) ;
writer.println ( "Command '" + clientRequest
+ "' not understood." ) ;
}
}
} catch ( IOException e ) {
System.out.println ( "error: IOException in Server " + e ) ;
System.exit ( 0 ) ;
}
}
}
}
2.2.1. 客户E序
package log4j ;
import java.io.* ;
import java.net.* ;
// add for log4j: import some package
import org.apache.log4j.PropertyConfigurator ;
import org.apache.log4j.Logger ;
import org.apache.log4j.Level ;
/**
*
* <p> Client With Log4j </p>
* <p> Description: a sample with log4j</p>
* @version 1.0
*/
public class ClientWithLog4j {
/*
add for log4j: class Logger is the central class in the log4j package.
we can do most logging operations by Logger except configuration.
getLogger(...): retrieve a logger by name, if not then create for it.
*/
static Logger logger = Logger.getLogger
( ClientWithLog4j.class.getName () ) ;
/**
*
* @param args : configuration file name
*/
public static void main ( String args [] ) {
String welcome = null ;
String response = null ;
BufferedReader reader = null ;
PrintWriter writer = null ;
InputStream in = null ;
OutputStream out = null ;
Socket client = null ;
/*
add for log4j: class BasicConfigurator can quickly configure the package.
print the information to console.
*/
PropertyConfigurator.configure ( "ClientWithLog4j.properties" ) ;
// add for log4j: set the level
// logger.setLevel ( ( Level ) Level.DEBUG ) ;
try{
client = new Socket( "localhost" , 8001 ) ;
// add for log4j: log a message with the info level
logger.info ( "Client socket: " + client ) ;
in = client.getInputStream () ;
out = client.getOutputStream () ;
} catch ( IOException e ) {
// add for log4j: log a message with the error level
logger.error ( "IOException : " + e ) ;
System.exit ( 0 ) ;
}
try{
reader = new BufferedReader ( new InputStreamReader ( in ) ) ;
writer = new PrintWriter ( new OutputStreamWriter ( out ), true ) ;
welcome = reader.readLine () ;
// add for log4j: log a message with the debug level
logger.debug ( "Server says: '" + welcome + "'" ) ;
// add for log4j: log a message with the debug level
logger.debug ( "HELLO" ) ;
writer.println ( "HELLO" ) ;
response = reader.readLine () ;
// add for log4j: log a message with the debug level
logger.debug ( "Server responds: '" + response + "'" ) ;
// add for log4j: log a message with the debug level
logger.debug ( "HELP" ) ;
writer.println ( "HELP" ) ;
response = reader.readLine () ;
// add for log4j: log a message with the debug level
logger.debug ( "Server responds: '" + response + "'") ;
// add for log4j: log a message with the debug level
logger.debug ( "QUIT" ) ;
writer.println ( "QUIT" ) ;
} catch ( IOException e ) {
// add for log4j: log a message with the warn level
logger.warn ( "IOException in client.in.readln()" ) ;
System.out.println ( e ) ;
}
try {
Thread.sleep ( 2000 ) ;
} catch ( Exception ignored ) {}
}
}
2.2.2. 服务器程?/strong>
package log4j;
import java.util.* ;
import java.io.* ;
import java.net.* ;
// add for log4j: import some package
import org.apache.log4j.PropertyConfigurator ;
import org.apache.log4j.Logger ;
import org.apache.log4j.Level ;
/**
*
* <p> Server With Log4j </p>
* <p> Description: a sample with log4j</p>
* @version 1.0
*/
public class ServerWithLog4j {
final static int SERVER_PORT = 8001 ; // this server's port
/*
add for log4j: class Logger is the central class in the log4j package.
we can do most logging operations by Logger except configuration.
getLogger(...): retrieve a logger by name, if not then create for it.
*/
static Logger logger = Logger.getLogger
( ServerWithLog4j.class.getName () ) ;
/**
*
* @param args
*/
public static void main ( String args[]) {
String clientRequest = null ;
BufferedReader reader = null ;
PrintWriter writer = null ;
ServerSocket server = null ;
Socket socket = null ;
InputStream in = null ;
OutputStream out = null ;
/*
add for log4j: class BasicConfigurator can quickly configure the package.
print the information to console.
*/
PropertyConfigurator.configure ( "ServerWithLog4j.properties" ) ;
// add for log4j: set the level
// logger.setLevel ( ( Level ) Level.DEBUG ) ;
try{
server = new ServerSocket ( SERVER_PORT ) ;
// add for log4j: log a message with the info level
logger.info ( "ServerSocket before accept: " + server ) ;
// add for log4j: log a message with the info level
logger.info ( "Java server with log4j, on-line!" ) ;
// wait for client's connection
socket = server.accept() ;
// add for log4j: log a message with the info level
logger.info ( "ServerSocket after accept: " + server ) ;
in = socket.getInputStream() ;
out = socket.getOutputStream() ;
} catch ( IOException e ) {
// add for log4j: log a message with the error level
logger.error ( "Server constructor IOException: " + e ) ;
System.exit ( 0 ) ;
}
reader = new BufferedReader ( new InputStreamReader ( in ) ) ;
writer = new PrintWriter ( new OutputStreamWriter ( out ), true ) ;
// send welcome string to client
writer.println ( "Java server with log4j, " + new Date () ) ;
while ( true ) {
try {
// read from client
clientRequest = reader.readLine () ;
// add for log4j: log a message with the debug level
logger.debug ( "Client says: " + clientRequest ) ;
if ( clientRequest.startsWith ( "HELP" ) ) {
// add for log4j: log a message with the debug level
logger.debug ( "OK!" ) ;
writer.println ( "Vocabulary: HELP QUIT" ) ;
}
else {
if ( clientRequest.startsWith ( "QUIT" ) ) {
// add for log4j: log a message with the debug level
logger.debug ( "OK!" ) ;
System.exit ( 0 ) ;
}
else {
// add for log4j: log a message with the warn level
logger.warn ( "Command '"
+ clientRequest + "' not understood." ) ;
writer.println ( "Command '"
+ clientRequest + "' not understood." ) ;
}
}
} catch ( IOException e ) {
// add for log4j: log a message with the error level
logger.error( "IOException in Server " + e ) ;
System.exit ( 0 ) ;
}
}
}
}
2.2.3. 配置文g
2.2.3.1. 客户E序配置文g
log4j.rootLogger=INFO, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n
2.2.3.2. 服务器程序配|文?/p>
log4j.rootLogger=INFO, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n
比较q两个应用可以看出,采用Log4jq行日志操作的整个过E相当简单明了,与直接用System.out.println语句q行日志信息输出的方式相比,基本上没有增加代码量Q同时能够清楚地理解每一条日志信息的重要E度。通过控制配置文gQ我们还可以灉|CҎ志信息的格式Q输出目的地{等斚wQ而单U依靠System.out.println语句Q显焉要做更多的工作?/p>
下面我们以前面使用Log4j的应用作Z子,详细讲解使用Log4j的主要步骤?/p>
Log4j׃个重要的lg构成Q日志信息的优先U,日志信息的输出目的地Q日志信息的输出格式。日志信息的优先U从高到低有ERROR、WARN、INFO、DEBUGQ分别用来指定这条日志信息的重要E度Q日志信息的输出目的地指定了日志打印到控制台还是文件中Q而输出格式则控制了日志信息的昄内容?/p>
其实您也可以完全不用配|文Ӟ而是在代码中配置Log4j环境。但是,使用配置文g您的应用E序更加灉|?/p>
Log4j支持两种配置文g格式Q一U是XML格式的文Ӟ一U是JavaҎ文Ӟ?|。下面我们介l用JavaҎ文件做为配|文件的ҎQ?/p>
log4j.rootLogger = [ level ] , appenderName, appenderName, ?其中Qlevel 是日志记录的优先U,分ؓOFF、FATAL、ERROR、WARN、INFO、DEBUG、ALL或者您定义的别。Log4j只用四个别,优先U从高到低分别是ERROR、WARN、INFO、DEBUG。通过在这里定义的U别Q您可以控制到应用程序中相应U别的日志信息的开兟뀂比如在q里定义了INFOU别Q则应用E序中所有DEBUGU别的日志信息将不被打印出来?br/>appenderName是指定日志信息输出到哪个地斏V您可以同时指定多个输出目的地?br/>
log4j.appender.appenderName = fully.qualified.name.of.appender.class log4j.appender.appenderName.option1 = value1 ?log4j.appender.appenderName.option = valueN其中QLog4j提供的appender有以下几U:
log4j.appender.appenderName.layout = fully.qualified.name.of.layout.class log4j.appender.appenderName.layout.option1 = value1 ?log4j.appender.appenderName.layout.option = valueN其中QLog4j提供的layout有以下几U:
下面讲q在E序代码中怎样使用Log4j?/p>
3.2.1.得到记录?/strong>
使用Log4jQ第一步就是获取日志记录器Q这个记录器负责控制日志信息。其语法为:
public static Logger getLogger( String name)Q?通过指定的名字获得记录器Q如果必要的话,则ؓq个名字创徏一个新的记录器。Name一般取本类的名字,比如Q?br/>
static Logger logger = Logger.getLogger ( ServerWithLog4j.class.getName () ) ;
3.2.2.d配置文g
当获得了日志记录器之后,W二步将配置Log4j环境Q其语法为:
BasicConfigurator.configure ()Q?自动快速地使用~省Log4j环境?br/>PropertyConfigurator.configure ( String configFilename) Q读取用Java的特性文件编写的配置文g?br/>DOMConfigurator.configure ( String filename ) Q读取XML形式的配|文件?/p>
3.2.3.插入记录信息Q格式化日志信息Q?/strong>
当上两个必要步骤执行完毕Q您可以轻村֜使用不同优先U别的日志记录语句插入到您想记录日志的Q何地方,其语法如下:
Logger.debug ( Object message ) ; Logger.info ( Object message ) ; Logger.warn ( Object message ) ; Logger.error ( Object message ) ;
如果您想更深入地了解Log4jQ请l常讉K下面提及的相关链接?br/>Log4j目主页------------------------------------------------------http://www.log4j.org/
Log4j FAQ -------------------------------------------------------http://www-900.ibm.com/developerWorks/cn/java/l-log4j/www.log4j.org/log4j/faq.html
当一个代码项目大了以后,每次重新~译Q打包,试{都会变得非常复杂而且重复Q因此c语言中有make脚本来帮助这些工作的扚w完成。在Java中应用是q_无关性的Q当然不会用q_相关的make脚本来完成这些批处理d了,ANT本n是q样一个流E脚本引擎,用于自动化调用程序完成项目的~译Q打包,试{。除了基于JAVA是^台无关的外,脚本的格式是ZXML的,比make脚本来说q要好维护一些?br/>
每个ant脚本Q缺省叫build.xmlQ中讄了一pdd(target)Q比如对于一个一般的目可能需要有以下d?/span>
<project default="usage" basedir="."> <!-- =================================================================== --> <!-- Initialization target --> <!-- =================================================================== --> <target name="init"> <tstamp/> <property file="${basedir}/build.properties" /> <property name="Name" value="ProjectFullName"/> <property name="name" value="project_name"/> <property name="version" value="0.2"/> <property name="year" value="2003"/> <echo message="----------- ${Name} ${version} [${year}] ------------"/> <property name="debug" value="off"/> <property name="optimize" value="on"/> <property name="deprecation" value="on"/> <property name="src.dir" value="./src/WEB-INF/src"/> <property name="lib.dir" value="./src/WEB-INF/lib"/> <property name="packages" value="com.chedong.*,org.apache.lucene.*"/> <property name="build.src" value="./src/WEB-INF/build"/> <property name="build.dest" value="./src/WEB-INF/classes"/> <property name="build.javadocs" value="./src/doc"/> <path id="classpath"> <pathelement path="${jsdk_jar}"/> <fileset dir="${lib.dir}"> <include name="**/*.jar"/> </fileset> </path> <filter token="year" value="${year}"/> <filter token="version" value="${version}"/> <filter token="date" value="${TODAY}"/> <filter token="log" value="true"/> <filter token="verbose" value="true"/> </target> <!-- =================================================================== --> <!-- Help on usage --> <!-- =================================================================== --> <target name="usage" depends="init"> <echo message="${Name} Build file"/> <echo message="-------------------------------------------------------------"/> <echo message=""/> <echo message=" available targets are:"/> <echo message=""/> <echo message=" jar --> generates the ${name}.jar file"/> <echo message=" build --> compiles the source code"/> <echo message=" javadoc --> generates the API documentation"/> <echo message=" clean --> cleans up the directory"/> <echo message=""/> <echo message=" Please rename build.properties.default to build.properties"/> <echo message=" and edit build.properties to specify JSDK 2.3 classpath."/> <echo message=""/> <echo message=" See the comments inside the build.xml file for more details."/> <echo message="-------------------------------------------------------------"/> <echo message=""/> <echo message=""/> </target> <!-- =================================================================== --> <!-- Prepares the source code --> <!-- =================================================================== --> <target name="prepare-src" depends="init"> <!-- create directories --> <mkdir dir="${build.src}"/> <mkdir dir="${build.dest}"/> <!-- copy src files --> <copy todir="${build.src}"> <fileset dir="${src.dir}"/> </copy> </target> <!-- =================================================================== --> <!-- Compiles the source directory --> <!-- =================================================================== --> <target name="build" depends="prepare-src"> <javac srcdir="${build.src}" destdir="${build.dest}" debug="${debug}" optimize="${optimize}"> <classpath refid="classpath"/> </javac> </target> <!-- =================================================================== --> <!-- Creates the class package --> <!-- =================================================================== --> <target name="jar" depends="build"> <jar jarfile="${lib.dir}/${name}.jar" basedir="${build.dest}" includes="**"/> </target> <!-- =================================================================== --> <!-- Creates the API documentation --> <!-- =================================================================== --> <target name="javadoc" depends="build"> <mkdir dir="${build.javadocs}"/> <javadoc packagenames="${packages}" sourcepath="${build.src}" destdir="${build.javadocs}" author="true" version="true" use="true" splitindex="true" windowtitle="${Name} API" doctitle="${Name}"> <classpath refid="classpath"/> </javadoc> </target> <!-- =================================================================== --> <!-- Clean targets --> <!-- =================================================================== --> <target name="clean" depends="init"> <delete dir="${build.src}"/> <delete dir="${build.dest}/org"/> <delete dir="${build.dest}/com"/> <delete> <fileset dir="${build.dest}" includes="**/*.class"/> </delete> </target> </project> <!-- End of file --> |
~省dQusage 打印帮助文Q告诉有那些d选项Q可用的有build, jar, javadoc和clean.
初始化环境变量:init
所有Q务都Z一些基本环境变量的讄初始化完成,是后l其他Q务的基础Q在环境初始化过E中Q有2Ҏ较可以方便设|:
1 除了使用却缺省的property讄了JAVA源\径和输出路径外,引用了一个外部的build.properties文g中的讄Q?br/><property file="${basedir}/build.properties" />
q样大部分简单配|用户只要会看懂build.properties可以了Q毕竟XML比vkey value的属性文件还是要可读性差一些。用build.properties也可以方便其他用户从~译的细节中解放出来?br/>
2 CLASSPATH讄Q用了其中的:
<path id="classpath"> <pathelement path="${jsdk_jar}"/> <fileset dir="${lib.dir}"> <include name="**/*.jar"/> </fileset> </path> |
则相当于讄了:CLASSPATH=/path/to/resin/lib/jsdk23.jar;/path/to/project/lib/*.jar;
文g复制Qprepare-src
创徏临时SRC存放目录和输出目录?/span>
<!-- =================================================================== --> <!-- Prepares the source code --> <!-- =================================================================== --> <target name="prepare-src" depends="init"> <!-- create directories --> <mkdir dir="${build.src}"/> <mkdir dir="${build.dest}"/> <!-- copy src files --> <copy todir="${build.src}"> <fileset dir="${src.dir}"/> </copy> </target> |
~译dQbuild
~译时的CLASSPATH环境通过一下方式找到引用一个path对象
<classpath refid="classpath"/> |
打包dQjar
对应用打包生成项目所写名?jar文g
<!-- =================================================================== --> <!-- Creates the class package --> <!-- =================================================================== --> <target name="jar" depends="build"> <jar jarfile="${lib.dir}/${name}.jar" basedir="${build.dest}" includes="**"/> </target> 生成JAVADOC文档d: javadoc <!-- =================================================================== --> <!-- Creates the API documentation --> <!-- =================================================================== --> <target name="javadoc" depends="build"> <mkdir dir="${build.javadocs}"/> <javadoc packagenames="${packages}" sourcepath="${build.src}" destdir="${build.javadocs}" author="true" version="true" use="true" splitindex="true" windowtitle="${Name} API" doctitle="${Name}"> <classpath refid="classpath"/> </javadoc> </target> 清空临时~译文gQclean <!-- =================================================================== --> <!-- Clean targets --> <!-- =================================================================== --> <target name="clean" depends="init"> <delete dir="${build.src}"/> <delete dir="${build.dest}/org"/> <delete dir="${build.dest}/com"/> <delete> <fileset dir="${build.dest}" includes="**/*.class"/> </delete> </target> |
TODOQ?br/>更多d/扩展Q(样例Q?br/>