Use eclipse and ajdt to develop aspectj applications (1)-Basics

Source: Internet
Author: User
Eclipse and AOP are currently hot topics, and AspectJ is the most mature in AOP technology. This article briefly introduces how to develop AspectJ applications in Eclipse. AJDT is a plug-in developed by the AspectJ project for Eclipse and is used to develop and run the AspectJ application. This article assumes that you have some knowledge about Eclipse and AspectJ. 1. Set the development environment first:  1. Download The AJDT plug-in. Of course, the idea must be implemented by Eclipse. In this version, AJDT corresponds to Eclipse V3.0.2, jdk3 is configured, and plug-ins are installed in Eclipse. There are two common methods: Method 1: decompress the downloaded plug-in package and copy the plugin and feature folders to the corresponding directory in Eclipse. Method 2: Select Help> Software Updates> Find and Install, select the downloaded package 4. Choose windows> custom perspective> select aspect in new. Then, aspectJ-related options will appear in "new. 2. Then let's write the simplest helloworld1. Create an aspectproject. Remember to add the Lib step required for compiling aspectj in build setting: Add variable-> select aspectjrt_lib. Otherwise, the aspectj program cannot be compiled. 2. Create a new class, as shown below: /** created on 2005-7-21 ** Java Thread Programming-Paul Hyde * copyright? 1999 SAMs publishing * Jonathan Q. bo Study Notes **/package Org. tju. msnrl. jonathan. aspect;/*** @ author Jonathan Q. bo from tju msnrl ** E-mail: jonathan.q.bo@gmail.com * blog: blog.csdn.net/jonathan_q_bo * blog.yesky.net/jonathanundersun ** enjoy life with sun! **/Public class helloworld {public static void main (string [] ARGs) {New helloworld (). sayhello ();} public void sayhello () {system. out. println ("Hello! ") ;}} 3. Create an aspect, as shown below:/** created on 2005-7-22 ** Java Thread Programming-Paul Hyde * copyright? 1999 SAMs publishing * Jonathan Q. bo Study Notes **/package Org. tju. msnrl. jonathan. aspect;/*** @ author Jonathan Q. bo from tju msnrl ** E-mail: jonathan.q.bo@gmail.com * blog: blog.csdn.net/jonathan_q_bo * blog.yesky.net/jonathanundersun ** enjoy life with sun! **/Public aspect aspecthelloworld { PointcutGreeting (): Call(Void HelloWorld. sayHello ()); After() Returning: Greeting () {system. out. println ("world") ;}} 4. Save the settings in helloworld. right-click Java and choose run-> aspectj/application. Is that simple? The tool can run this program, and the rest is familiar with the aspectj syntax. [Reference] 1. Eclipse self-contained routine: helloworld (Help-> welcome-> simple aspectj application) 2. To view the source program, you can directly create an aspectj routine: right-click on package perspective New-> introduction example and include many example3, http://blog.csdn.net/jonathan_q_bo/articles/430893.aspx
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.