分享
 
 
 

将AspectJ集成到基于Eclipse + Lomboz + XmlBuddy的Web应用中去 - 基础篇

王朝java/jsp·作者佚名  2006-01-31
窄屏简体版  字體: |||超大  

一、 配置eclipes开发环境

首先,下载需要的插件:

eclipse-SDK-3.0.2-win32

Eclipse IDE

官方下载地址:

http://download.eclipse.org/downloads/drops/R-3.0.2-200503110845/eclipse-SDK-3.0.2-win32.zi

xmlbuddy_2.0.62

用于xml开发,可以用来编辑web.xml文件

官方下载地址:http://www.xmlbuddy.com/

org.objectweb.lomboz_3.0.1.N20050106

用于web开发,支持jsp,servlet等等的高亮显示和编辑

官方下载地址:http://forge.objectweb.org/projects/lomboz/

ajdt_1.2_for_eclipse_3.0

用于AspectJ开发,专为eclipse开发的AspectJ插件

官方下载地址:http://www.xmlbuddy.com/

VE-runtime-1.0.2.2

安装以上两个插件时必备,一个相关的类包含在此插件中。The Eclipse Visual Editor project is a vendor-neutral, open development platform supplying frameworks for creating GUI builders, and exemplary, extensible tool implementations for Swing/JFC and SWT/RCP. These tools are exemplary in that they verify the utility of the Eclipse Visual Editor frameworks, illustrate the appropriate use of those frameworks, and support the development and maintenance of the Eclipse Visual Editor Platform itself.

官方下载地址:http://www.xmlbuddy.com/

GEF-runtime-3.0.1

安装VE时必备,The Graphical Editing Framework (GEF) allows developers to take an existing application model and quickly create a rich graphical editor.

官方下载地址:

http://download.eclipse.org/tools/gef/downloads/drops/R-3.0.1-200408311615/GEF-runtime-3.0.1.zip

emf-sdo-runtime-2.0.2

安装VE时必备,EMF is a modeling framework and code generation facility for building tools and other applications based on a structured data model. From a model specification described in XMI, EMF provides tools and runtime support to produce a set of Java classes for the model, a set of adapter classes that enable viewing and command-based editing of the model, and a basic editor. Models can be specified using annotated Java, XML documents, or modeling tools like Rational Rose, then imported into EMF. Most important of all, EMF provides the foundation for interoperability with other EMF-based tools and applications.

官方下载地址:

http://download.eclipse.org/tools/emf/downloads/drops/2.0.2/R200503151315/emf-sdo-runtime-2.0.2.zip

[说明] 现在最高版本的ajdt支持到eclipse3.0.2,所以相应的其他插件都选择与eclipse相对应的最高版本。

2、下载完成后解压进行安装:help -> softwareupdate -> find and install -> …from local….

3、进行配置window -> perspective

配置aspectj:

不需要特别配置

配置lomboz:

A、设置jdk tools.jar位置,为安装的j2sdk目录

B、配置server definition:选择Apache Tomcat : tomcat5.0.x,设置其Server lib和project lib,可以把%tomcat_home%/common/lib一些相关的包都放进去,有可能是必须放,注意,某些版本据说可能是5.0.27,需要修改目录E:\eclipse3.0.2\plugins\com.objectlearn.jdt.j2ee_3.0.1

\servers,tomcat5.0.x配置文件tomcat50x.server文件,将两处-Djava.endorsed.dirs=,

修改为如下:

-Djava.endorsed.dirs="${serverRootDirectory}/common/endorsed"

4、配置window -> customize perspective,将aspectj和lomboz相关的项目都给添加到new中,这样就可以通过“新建“来建立相应的工程文件。

二、 集成AspectJ到Web工程中

5、新建一个AspectJ工程

6、在此工程中新建一个Lomboz J2EE Module

7、新建一个Servlet,并设置其url-mapping

/*

* Created on 2005-8-3 ,test

*

* @Author:Jonathan Q. Bo from tju.msnrl

* MyBlog:http://blog.csdn.net/jonathan_q_bo

*

*/

package org.tju.msnrl.jonathan.aspectj;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.ServletOutputStream;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

/**

* @author Administrator

* 2005-8-3 14:46:22

*/

public class HelloWorld extends HttpServlet {

public void doGet(HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException {

//TODO Method stub generated by Lomboz

ServletOutputStream out = response.getOutputStream( );

out.println("<h1>Hello World from an aspect-oriented Servlet!</h1>");

}

}

8、新建一个Aspect,拦截其doGet(..),在其执行之前和之后作相应的advice

/*

* Created on 2005-8-3 ,test

*

* @Author:Jonathan Q. Bo from tju.msnrl

* MyBlog:http://blog.csdn.net/jonathan_q_bo

*

*/

package org.tju.msnrl.jonathan.aspectj;

import java.io.IOException;

import javax.servlet.ServletOutputStream;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

/**

* @author Administrator

* 2005-8-3 15:43:54

*/

public aspect HelloWorldAspect {

public pointcut captureHttpRequest(HttpServletRequest request,

HttpServletResponse response) :

execution(public void HelloWorld.doGet(HttpServletRequest,

HttpServletResponse)) &&

args(request, response);

before(HttpServletRequest request, HttpServletResponse response)

throws IOException :

captureHttpRequest(request, response)

{

response.setContentType("text/html");

ServletOutputStream out = response.getOutputStream( );

out.println("<html>");

out.println("<head><title>Adding a title using AspectJ!</title></head>");

out.println("<body>");

}

after(HttpServletRequest request, HttpServletResponse response)

throws IOException :

captureHttpRequest(request, response)

{

ServletOutputStream out = response.getOutputStream( );

out.println("</body>");

out.println("</html>");

}

}

9、部署工程,默认会将工程打包成war文件部署,试验发现,war文件执行时会报错,所以,需要改写build.xml文件,原build.xml文件将编译好的文件统一放到dist文件夹中,然后对其打包war,简单修改,只需要将打包过程去掉,将dist文件夹直接拷贝到tomcat_home/webapps/下就可以了

<project name="webmodulebuilder" default="deploy" basedir=".">

<!-- set global properties for this build -->

<property file="build.properties"/>

<property name="dist" value="../../dist" />

<property name="deploy.dir" value="C:/Program Files/Apache Software Foundation/Tomcat 5.0/webapps/rbac" />

<property name="web" value="../" />

<target name="init">

<!-- Create the dist directory structure used by compile

and copy the deployment descriptors into it-->

<mkdir dir="${dist}"/>

<mkdir dir="${dist}/WEB-INF"/>

<mkdir dir="${dist}/WEB-INF/classes"/>

<mkdir dir="${dist}/WEB-INF/lib"/>

<copy todir="${dist}">

<fileset dir="${web}">

<include name="**/*.*"/>

<exclude name="**/*.java"/>

<exclude name="**/jsp_servlet/*.class"/>

<exclude name="**/build.xml"/>

<exclude name="**/deploy.xml"/>

<exclude name="**/build.properties"/>

<exclude name="**/servers.xml"/>

<exclude name="**/targets.xml"/>

<exclude name="**/*.war"/>

</fileset>

</copy>

<copy todir="${dist}/WEB-INF/classes">

<fileset dir="${project.dir}/${bin.dir}">

<include name="**/*.*"/>

<exclude name="**/jsp_servlet/*.class"/>

<exclude name="**/*.java"/>

</fileset>

</copy>

</target>

<target name="deploy" depends="undeploy,init" >

<mkdir dir="${deploy.dir}/rbac"/>

<copy todir="${deploy.dir}/rbac">

<fileset dir="${dist}">

<include name="**/*.*"/>

</fileset>

</copy>

<!-- Create the distribution directory -->

<!--<delete file="${war}.war" failonerror="false" />

<jar jarfile="${war}.war" basedir="${dist}" manifest="${dist}/META-INF/MANIFEST.MF"/>

<copy file="${war}.war" todir="${deploy.dir}"/>-->

<!--<delete file="${war}.war" failonerror="false" />-->

<!--<delete dir="${dist}" failonerror="false" />-->

</target>

<target name="deployTool">

<ant antfile="./deploy.xml" dir="." target="deploy" inheritall="true">

</ant>

</target>

<target name="undeploy">

<!-- Sometimes you can undeploy with deleting the module file but it is best dealt on an appserver basis

at undeployTool target -->

</target>

<target name="undeployTool">

<ant antfile="./undeploy.xml" dir="." target="undeploy" inheritall="true">

</ant>

</target>

</project>

10、打开J2EE Lamboz View,选中Lomboz J2ee Module -> 部署 deploy -> 运行服务器 Run server

11、在浏览器中输入地址访问,会出现如下结果,

Hello World from an aspect-oriented Servlet!

成功!

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有