AspectJ
| Company type | Open-source software project |
|---|---|
| Industry | Software development, Programming tools |
| Founded | 2001 |
| Founder | Gregor Kiczales and team at Xerox PARC |
Area served | Worldwide |
Key people | Alexander Kriegisch (lead maintainer as of 2024), Gregor Kiczales, Jim Hugunin, Erik Hilsdale, Mik Kersten, Adrian Colyer, Andrew Clement |
| Products | AspectJ (AOP extension for Java), AspectJ Development Tools (AJDT) |
| Owner | Eclipse Foundation (maintainer) |
| Parent | Eclipse Foundation |
| Website | www |
AspectJ represents an aspect-oriented programming (AOP) enhancement tailored for the Java platform, initially created at PARC and currently maintained as part of the Eclipse Foundation's open-source initiatives. Offered both as a standalone tool and integrated within Eclipse, AspectJ has established itself as the predominant standard for AOP by emphasizing ease of use and straightforwardness. Utilizing syntax similar to Java, it features IDE capabilities that visualize crosscutting elements since its introduction in 2001.
Plain language overview
Every valid Java program is inherently a valid AspectJ program; however, AspectJ extends conventional classes by introducing unique constructs known as aspects which provide additional functionalities:
- Extension methods
- Allow incorporation of new methods, fields, or interfaces into existing classes from within an aspect. For example, injecting an
acceptVisitormethod into thePointclass:
- <syntaxhighlight lang="aspectj">
aspect VisitAspect {
void Point.acceptVisitor(Visitor v) {
v.visit(this);
}
} </syntaxhighlight>
- Pointcuts
- Specify join points—precise moments during execution such as method invocations or object constructions—using expressions that identify these points. For example, this pointcut captures any instance method in
Pointwhose name begins withset:
- <syntaxhighlight lang="aspectj">
pointcut set() : execution(* set*(..) ) && this(Point); </syntaxhighlight>
- Advices
- Define code snippets to execute at join points matched by a pointcut, which can be triggered before, after, or around the join point. The following example updates the display after any matched
setmethod completes:
- <syntaxhighlight lang="aspectj">
after () : set() {
Display.update();
} </syntaxhighlight>
Additionally, AspectJ offers limited static checking based on pointcuts and supports aspect reuse through inheritance. For an in-depth understanding, refer to the AspectJ Programming Guide.
Compatibility and implementation approaches
AspectJ implementations can be realized through source-weaving, bytecode-weaving, or direct integration into the virtual machine (VM), producing Java-compliant programs executable on any standard Java VM. Classes influenced by aspects remain binary-compatible with those unaffected, facilitating seamless interoperability. The availability of multiple implementation strategies accommodates technological advancements, while adherence to Java standards ensures extensive platform support.
Key engineering decisions have been pivotal in AspectJ's widespread adoption by enhancing usability and simplifying deployment. The initial Xerox prototype employed source weaving requiring access to source code. Following its contribution to Eclipse, AspectJ was redeveloped utilizing the Eclipse Java compiler alongside a bytecode weaver built on BCEL, enabling aspect development directly on compiled (.class) files. This transition introduced a per-class model crucial for incremental compilation and load-time weaving, resulting in improved IDE responsiveness and allowing deployment without modifications to existing build workflows. These improvements significantly increased acceptance among enterprise-level Java developers.
Subsequent enhancements by the Eclipse team include performance optimizations, accuracy improvements, and incorporation of Java 5 features such as generics and annotations. They also merged annotation-style pure-Java aspects from AspectWerkz. Eclipse provides both command-line and Ant interfaces, while the AspectJ Development Tools (AJDT) plugin enriches Eclipse IDE integration. Although support for other IDEs like emacs, NetBeans, and JBuilder diminished post open-sourcing, Oracle's JDeveloper maintained compatibility. Comprehensive IDE support has been instrumental for Java developers adopting AspectJ and managing crosscutting concerns effectively.
While BEA offered limited virtual machine support for aspect-oriented extensions, widespread implementation across Java VMs would necessitate consensus through Sun's Java Community Process. The introduction of the java.lang.instrument package (available since Java SE 5) provides a standardized mechanism for JVM load-time instrumentation.
Academic interest in AspectJ continues robustly, with the foremost research tool being the AspectBench Compiler (abc), which facilitates syntax and semantic enhancements allowing advanced AOP experimentation beyond what is supported by core AspectJ development.
Many practitioners first engage with AspectJ indirectly via enabling frameworks such as the Spring AOP. The related Spring Roo project relies heavily on AspectJ inter-type declarations as its fundamental code generation technique.
History and key contributors
The development of AspectJ was spearheaded by Gregor Kiczales and his team at Xerox PARC, who also introduced the concept of crosscutting. The term aspect-oriented programming was coined by Chris Maeda. The initial compiler and weaver were created by Jim Hugunin and Erik Hilsdale, while Mik Kersten took charge of integrating AspectJ with IDEs and launched the Eclipse AJDT initiative alongside Adrian Colyer and Andrew Clement. Following Colyer’s involvement, Clement assumed the role of principal contributor and project leader. Although AJDT has been merged under the Eclipse AspectJ umbrella for simplified upkeep, both AspectJ and AJDT are maintained in distinct repositories.
In 2021, Alexander Kriegisch began contributing to the project and eventually became its sole maintainer. As of 2024, he officially serves as the lead for both the AspectJ and AJDT projects.
The AspectBench Compiler is a collaborative effort developed by the Programming Tools Group at Oxford University Computing Laboratory, the Sable Research Group at McGill University, and the BRICS Institute.
AspectWerkz
AspectWerkz was a lightweight, dynamic AOP framework designed for Java, which was incorporated into AspectJ in 2006. Its features have been supported in AspectJ since version 5.
Created by Jonas Boner and Alex Vasseur, AspectWerkz introduced annotation-based aspects and load-time weaving capabilities to AspectJ. Unlike pre-5 versions of AspectJ, it did not extend the language syntax but instead declared aspects using Java annotations. It modifies bytecode to weave classes during build-time, class loading, or runtime through JVM-level APIs. Aspects could be defined using Java annotations, custom doclets for Java 1.3/1.4, or XML configuration files.
AspectWerkz also provides an API that applies aspects as proxies, facilitating a seamless experience for users familiar with proxy-based design patterns.
Distributed under the LGPL license, AspectWerkz 2.0 supports both commercial applications and open-source projects.
See also
- Aspect-oriented programming
- Spring AOP (a component of the Spring Framework)
- Aspect-oriented software development
References
- Ramnivas Laddad, AspectJ in Action: Enterprise AOP with Spring, 2nd edition, Manning Publications, 2009, 550 pages, ISBN 978-1-933988-05-4
- Russ Miles, AspectJ Cookbook, O'Reilly Media, 2004, 354 pages, ISBN 978-0-596-00654-9
- Adrian Colyer et al., Eclipse AspectJ: Aspect-Oriented Programming with AspectJ and the Eclipse AspectJ Development Tools, Addison-Wesley Professional, 2004, 504 pages, ISBN 978-0-321-24587-8
- Joseph D. Gradecki & Nicholas Lesiecki, Mastering AspectJ: Aspect-Oriented Programming in Java, Wiley, 2003, 456 pages, ISBN 978-0-471-43104-6
External links
- AJDT
- Aspect bench
- AspectJ Home Page
- AspectWerkz Project homepage
- Improve modularity with aspect-oriented programming
- Spring AOP and AspectJ Introduction
- The AspectJ Programming Guide
Xerox holds US patent number 6467086 related to AOP/AspectJ but has made the AspectJ source code available under the Common Public License, which grants certain patent rights.
- Articles with short description
- Programming languages
- Aspect-oriented programming
- Aspect-oriented software development
- Cross-platform software
- Eclipse (software)
- Eclipse software
- Eclipse technology
- Java programming language family
- Software distribution
- Software using the Eclipse Public License
- Programming languages created in 2001
- 2001 software
- Cross-platform free software
- High-level programming languages