hook 与aspectj_将AspectJ与NetBeans平台开发集成
hook 与aspectj
您是否正在使用NetBeans平台开发项目? 您愿意使用AspectJ来使用AOP吗? 您不知道如何将AspectJ编译器集成到NetBeans的内部版本中?
如果您的回答是“是”,则此帖子适合您。
我决定写这篇技术文章,是因为我在寻找该解决方案之前一直很费力,所以我想分享一下。
讲故事
以前,我不得不面对将AspectJ集成到使用NetBeans Platform源代码实现的Rich Client Application中的问题。 做出的第一个决定是在编译级别集成AspectJ,以便创建包含AOP的已编译源代码。
主要问题是,如何将此后编译与netbeans ant编译文件集成在一起。
解决方案
首先让我们确定必须修改的文件:
第1步
下载AspectJ库,并将它们放在NetBeans安装的“ harness”文件夹内的文件夹中。 假设此文件夹名为:aspectj-xxx / lib。
第2步
进入包含要与AspectJ一起编译的源代码的模块,并在其project.properties文件(在重要文件中)中添加以下行:
aspectjcompiler=required第三步
现在是时候配置common.xml文件了。 启动构建操作时,NetBeans IDE调用的ant目标实际上位于此位置。
该示例是使用NetBeans 7.3.1完成的,但是对于以前或将来的更改差异很小。 修改以蓝色突出显示。
更改目标编译,如下所示:
<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>添加一个新的目标编译 ,如下所示:
<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>添加新的目标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>结论
现在,当您进行清理和构建时,您会看到所选模块的源代码在正常编译之后立即针对AspectJ编译器进行了编译。
您需要确保的是,方面和必须使用其进行编译的源代码都在同一模块中。
翻译自: https://www.javacodegeeks.com/2013/10/integrate-aspectj-with-netbeans-platform-development.html
hook 与aspectj
总结
以上是生活随笔为你收集整理的hook 与aspectj_将AspectJ与NetBeans平台开发集成的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 守护进程linux(守护进程 linux
- 下一篇: Apache Ignite,Hazelc