日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

hook 与aspectj_将AspectJ与NetBeans平台开发集成

發(fā)布時間:2023/12/3 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hook 与aspectj_将AspectJ与NetBeans平台开发集成 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

hook 與aspectj

您是否正在使用NetBeans平臺開發(fā)項目? 您愿意使用AspectJ來使用AOP嗎? 您不知道如何將AspectJ編譯器集成到NetBeans的內(nèi)部版本中?

如果您的回答是“是”,則此帖子適合您。

我決定寫這篇技術(shù)文章,是因為我在尋找該解決方案之前一直很費(fèi)力,所以我想分享一下。

講故事

以前,我不得不面對將AspectJ集成到使用NetBeans Platform源代碼實(shí)現(xiàn)的Rich Client Application中的問題。 做出的第一個決定是在編譯級別集成AspectJ,以便創(chuàng)建包含AOP的已編譯源代碼。

主要問題是,如何將此后編譯與netbeans ant編譯文件集成在一起。

解決方案

首先讓我們確定必須修改的文件:

  • common.xml:位于NetBeans安裝的線束文件夾中
  • project.properties:包含必須用AspectJ編譯的源代碼的模塊的
  • 第1步

    下載AspectJ庫,并將它們放在NetBeans安裝的“ harness”文件夾內(nèi)的文件夾中。 假設(shè)此文件夾名為:aspectj-xxx / lib。

    第2步

    進(jìn)入包含要與AspectJ一起編譯的源代碼的模塊,并在其project.properties文件(在重要文件中)中添加以下行:

    aspectjcompiler=required

    第三步

    現(xiàn)在是時候配置common.xml文件了。 啟動構(gòu)建操作時,NetBeans IDE調(diào)用的ant目標(biāo)實(shí)際上位于此位置。

    該示例是使用NetBeans 7.3.1完成的,但是對于以前或?qū)淼母牟町惡苄 ?修改以藍(lán)色突出顯示。

    更改目標(biāo)編譯,如下所示:

    <target name=”compile-nb-javac” depends=”init,up-to-date” unless=”is.jar.uptodate”> <mkdir dir=”${build.classes.dir}”/> <depend srcdir=”${src.dir}” destdir=”${build.classes.dir}” cache=”${build.dir}/depcache”> <classpath refid=”cp”/> </depend> <nb-javac srcdir=”${src.dir}” destdir=”${build.classes.dir}” debug=”${build.compiler.debug}” debuglevel=”${build.compiler.debuglevel}” encoding=”UTF-8″ deprecation=”${build.compiler.deprecation}” optimize=”${build.compiler.optimize}” source=”${javac.source}” target=”${javac.target}” includeantruntime=”false”> <classpath refid=”cp”/> <compilerarg line=”${javac.compilerargs}”/> <processorpath refid=”processor.cp”/> </nb-javac> <copy todir=”${build.classes.dir}”> <fileset dir=”${src.dir}” excludes=”${jar-excludes}”/> </copy> </target>

    添加一個新的目標(biāo)編譯 ,如下所示:

    <target name=”compile” depends=”init,up-to-date” unless=”is.jar.uptodate”> <mkdir dir=”${build.classes.dir}”/> <depend srcdir=”${src.dir}” destdir=”${build.classes.dir}” cache=”build/depcache”> <classpath refid=”cp”/> </depend> <antcall target=”compile-nb-javac” inheritAll=”true” /> <antcall target=”compile-aspectj” inheritAll=”true” /> </target>

    添加新的目標(biāo)compile-aspectj,如下所示:

    <target name=”compile-aspectj” depends=”init,up-to-date” unless=”is.jar.uptodate” if=”aspectjcompiler”> <property name=”cpProperty” refid=”cp”/> <property name=”aspectj.lib.dir” location=”${harness.dir}/aspectj-x.x.x/lib”/> <property name=”aspectjtools.jar” location=”${aspectj.lib.dir}/aspectjtools.jar”/> <property name=”aspectjrt.jar” location=”${aspectj.lib.dir}/aspectjrt.jar”/> <taskdef resource=”org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties”> <classpath> <pathelement path=”${aspectjtools.jar}”/> </classpath> </taskdef> <iajc destdir=”${build.classes.dir}” source=”${javac.source}” fork=”true” forkclasspath=”${aspectjtools.jar}” classpath=”${aspectjrt.jar};${cpProperty}” failonerror=”false” > <sourceroots> <pathelement location=”${src.dir}”/> </sourceroots> </iajc> </target>

    結(jié)論

    現(xiàn)在,當(dāng)您進(jìn)行清理和構(gòu)建時,您會看到所選模塊的源代碼在正常編譯之后立即針對AspectJ編譯器進(jìn)行了編譯。

    您需要確保的是,方面和必須使用其進(jìn)行編譯的源代碼都在同一模塊中。

    參考: Refactoring Ideas博客上的JCG合作伙伴 Marco Di Stefano 將AspectJ與NetBeans平臺開發(fā)集成 。

    翻譯自: https://www.javacodegeeks.com/2013/10/integrate-aspectj-with-netbeans-platform-development.html

    hook 與aspectj

    總結(jié)

    以上是生活随笔為你收集整理的hook 与aspectj_将AspectJ与NetBeans平台开发集成的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。