huyi

BlogJava 首页 新随笔 联系 聚合 管理
  46 Posts :: 5 Stories :: 5 Comments :: 0 Trackbacks

1 Overview

1. What is AspectJ?

AspectJ(tm) is a simple and practical extension to the Java(tm) programming language that adds to Java aspect-oriented programming (AOP) capabilities. AOP allows developers to reap the benefits of modularity for concerns that cut across the natural units of modularity. In object-oriented programs like Java, the natural unit of modularity is the class. In AspectJ, aspects modularize concerns that affect more than one class.

You compile your program using the AspectJ compiler (perhaps using the supported development environments) and then run it, supplying a small (< 100K) runtime library.

The AspectJ technologies include a compiler (ajc), a debugger (ajdb), a documentation generator (ajdoc), a program structure browser (ajbrowser), and integration with Eclipse, Sun-ONE/Netbeans, GNU Emacs/XEmacs, JBuilder, and Ant.

2. What are the benefits of using AspectJ?

AspectJ can be used to improve the modularity of software systems.

Using ordinary Java, it can be difficult to modularize design concerns such as

  • system-wide error-handling

  • contract enforcement

  • distribution concerns

  • feature variations

  • context-sensitive behavior

  • persistence

  • testing

The code for these concerns tends to be spread out across the system. Because these concerns won't stay inside of any one module boundary, we say that they crosscut the system's modularity.

AspectJ adds constructs to Java that enable the modular implementation of crosscutting concerns. This ability is particularly valuable because crosscutting concerns tend to be both complex and poorly localized, making them hard to deal with.

3. Can AspectJ work with any Java program?

AspectJ has been designed as a compatible extension to Java. By compatible, we mean

upward compatible All legal Java programs are legal AspectJ programs.
platform compatible All legal AspectJ programs run on standard Java virtual machines.
tool compatible Existing tools can be extended to work with AspectJ.
programmer compatible Programming in AspectJ feels natural to Java programmers.

The AspectJ tools run on any Java 2 Platform compatible platform. The AspectJ compiler produces classes that run on any Java 1.1 (or later) compatible platform.

4. How is AspectJ licensed?

AspectJ 1.1 source code and documentation is available under the Common Public License 1.0.

The AspectJ 1.0 tools are open-source software available under the Mozilla Public License 1.1. That documentation is available under a separate license that precludes for-profit or commercial redistribution.

Most users only want to use AspectJ to build programs they distribute. There are no restrictions here. When you distribute your program, be sure to include all the runtime classes from the aspectjrt.jar for that version of AspectJ. When distributing only the runtime classes, you need not provide any notice that the program was compiled with AspectJ or includes binaries from the AspectJ project, except as necessary to preserve the warranty disclaimers in our license.

5. What is the AspectJ Project?

AspectJ is based on over ten years of research at Xerox Palo Alto Research Center as funded by Xerox, a U.S. Government grant (NISTATP), and a DARPA contract.

It has evolved through open-source releases to a strong user community and now operates as an open source project at http://eclipse.org/aspectj The AspectJ team works closely with the community to ensure AspectJ continues to evolve as an effective aspect-oriented programming language and tool set.

The latest release is 1.2 which can be downloaded from the AspectJ project page, including sources as described Q:How do I get and compile the source code for AspectJ?. Development is focused on supporting applications, improving quality and performance, enhancing integration with IDE's, and building the next generations of the language.

2 Quick Start

1. What Java versions does AspectJ require and support?

The AspectJ compiler produces programs for any released version of the Java platform (jdk1.1 and later). When running, your program classes must be able to reach classes in the small (< 100K) runtime library (aspectjrt.jar) from the distribution. The tools themselves require J2SE 1.3 or later to run, but the compiler can produce classes for any 1.1-compliant version of the Java platform.

2. How do I download and install AspectJ?

From AspectJ's web page , download the AspectJ distribution. The jar file is installed by executing

            java -jar jar file name
          

Do not try to extract the jar file contents and then attempt to execute java org.aspectj.tools.Main. (A NoClassDefFoundError exception will be thrown.) The AspectJ distribution is not designed to be installed this way. Use the java -jar form shown above.

To uninstall, remove the files the installer wrote in your file system. In most cases, you can delete the top-level install directory (and all contained files), after you remove any new or updated files you want to keep. On Windows, no registry settings were added or changed, so nothing needs to be undone. Do not install over prior versions, which might have different files. Delete the prior version first.

3. How should I start using AspectJ?

Many users adopt AspectJ incrementally, first using it to understand and validate their systems (relying on it only in development) and then using it to implement crosscutting concerns in production systems. AspectJ has been designed to make each step discrete and beneficial.

In order of increasing reliance, you may use AspectJ:

  • In the development process Use AspectJ to trace or log interesting information. You can do this by adding simple AspectJ code that performs logging or tracing. This kind of addition may be removed ("unplugged") for the final build since it does not implement a design requirement; the functionality of the system is unaffected by the aspect.

  • As an ancillary part of your system Use AspectJ to more completely and accurately test the system. Add sophisticated code that can check contracts, provide debugging support, or implement test strategies. Like pure development aspects, this code may also be unplugged from production builds. However, the same code can often be helpful in diagnosing failures in deployed production systems, so you may design the functionality to be deployed but disabled, and enable it when debugging.

  • As an essential part of your system Use AspectJ to modularize crosscutting concerns in your system by design. This uses AspectJ to implement logic integral to a system and is delivered in production builds.

一:总揽

1什么是AspectJ
AspectJ是JAVA程序语言的简单并且实用的一种扩充。它增加了JAVA aspect-oriented progamming(AOP)即面向方面编程的工能。它能使程序员从模块单元的横切关系上获知益。像面向对象编语言JAVA,模块之间的一种自然的关联是建立在类。也就是class上的。在AspectJ中,这种关联会涉及到一多个模块。

你可以用aspectJ进行你的程序开发(不包括运行环境),一个运行库大约不到100k.

AspectJ 技术包括一个编译器ajc,一个调式器ajdb,一个通用文档ajdoc,一个程序结构浏览器ajbrowser,还有一个支持这个架构的运行环境,Eclipse,SUN-ONE/Netbeans,GUNEmacs/XEmacs,JBuilder,和Ant.

2使用AspectJ的好处


AspectJ可以用于改进软件模块的性能。
使用JAVA语言,在 处理系统异常(system-wide error-handling),契约式编程(contract enforcement),分布式(distribution concerns),可变性(feature variations),上下文相关行为(context-sensitive behavior),持久化(persistence),测试(testing)在这些方面,模块之间的关联很难设计。在这些方面,代码不能分布在整个系统中,而不能封装在一个类中,这便是系统中的一种横切关系。

AspectJ提供的构架使模块能够实现横切关系。实现系统中的横切关系是很有价值并且必要的,因为系统中这些分散于各个模块的代码,使我们的设计变得复杂,局部混乱,并且乱于管理与维护。

3AspectJ能应该于任何系统中吗?


AspectJ可以和任何JAVA程序兼容。这种兼容是包括以下几个方面

向上兼容:所有标准的JAVA程序,都是标准的Aspect程序。
平台兼容:所有标准的Aspect程序,都是运行于JAVA虚拟机上。
工具兼容:现有工具可以被延用到AspectJ中使用。
程序兼容:在AspectJ中编写的程序,对于JAVA程序来说,感觉也会很自然,很熟悉。


二:快速入门

1.AspectJ要求并支持的JAVA版本?

AspectJ可以为JAVA平台1.1以后的版本发布代码。运行时,你要使自己程序的类可以访问到AspectJ运行类aspectj.jar(这个包小于100k).

2.怎样下载AspectJ的安装文件?

从AspectJ的网页上,下载AspectJ的正式版。java-jar×××解压后,安装。


不要尝试分解jar文件的内容,或者分离工具包中的类。(NoClassDefFoundError exception 没有创建的类 这个异常会被抛出。 )不能这样安装.还是要按着解压后安装的方式,进行安装。

卸载时,要删除掉已经写入的文件。在大多情况下,再你把要保存的新的或刚刚更新过的文件移开时,你可以删除最上层的安装目录。在windows下,不用注册,所以不用做什么其它事情就可以正常使用了。不要覆盖安装当前版本,因为可能出现新的文件。安装新版本前,请删除原来的文件。

3怎样开始使用AspectJ

许多用户常常会先用AspectJ来了解验证自己的系统,然后再去用AspectJ去执行横切。AspectJ设计本意使设计阶段连续不间段的获利。

在以下几个方面你可以自信的使用AspectJ:

1在系统开发过程中:使用AspectJ来描述或记录特殊信息。你可以通过简单的AspectJ代码来实现日志记录和信息描述。如果系统不需要执行这些功能的时候,也可以把这个新增的功能最终的系统中拿掉,而原来的系统不会受任何的影响。

2系统的辅助部分:使用AspectJ来完善并且精确的测试你的系统。AspectJ增加了精典的代码来检查系统规范,支持检查系统漏洞,或者执行系统测试。就像AOP的本质一样,这些代码一样可以被从最终的系统中删除。这些代码在检查现有系统的问题的时候还是很有帮助的,所以我们可以把这功能设计出来,但是不在系统运行时,有实际的作用,而只在测试时产生作用。

3系统核心部分:使用AspectJ来对模块进行横切设计。这种使用AspectJ来对系统执行的逻辑规范将被包括在系统中。

posted on 2005-04-01 15:58 HuYi's Blog 阅读(1010) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: