Java - 为什么aspectj需要安装插件?

发布于 2024-12-19 17:49:58 字数 176 浏览 5 评论 0原文

所以我尝试在我的应用程序中使用 AOP 进行日志记录和一些错误处理。 大多数人推荐使用aspectj,所以我的问题是为什么aspectj需要我安装eclipse插件才能使用它? 不是aspectj只是使用反射来在运行时修改类吗?

我们还使用构建服务器,我是否还需要在构建服务器上安装任何东西才能使用aspectj运行项目?

So I am trying to use AOP in my application for logging and some error handling.
Most people recommended using aspectj, so my question is why does aspectj require me to install an eclipse plugin to be able to use it?
Doesn't aspectj simply use reflection to modify classes at run-time?

We are also using a build server , do I need to install anything on the build server as well in order to run a project using aspectj?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不疑不惑不回忆 2024-12-26 17:49:58

它不会,除非您特别想让 Eclipse 具有切面感知能力,并在其内部构建过程中包含 AspectJ 功能。 (IMO IDE 对 AOP 的支持很棒,并且使 AOP 更容易处理。光是装订线标记就值回票价了。)

AspectJ 修改字节码;你不能通过纯粹的反射来做它所做的事情,

你的构建服务器需要适当的库。如果您正在进行编译时编织,则需要将其添加到构建脚本中。

It doesn't, unless you specifically want to have Eclipse be aspect-aware, and include AspectJ functionality in its internal build process. (IMO IDE support for AOP is awesome, and makes AOP much easier to deal with. the gutter markings alone are worth the price of admission.)

AspectJ modifies byte-code; you cannot do what it does through pure reflection,

Your build server needs the appropriate libraries. If you're doing compile-time weaving, that needs to be added to the build script.

作死小能手 2024-12-26 17:49:58

Aspect-J 使用代理通过所谓的加载时编织来修改类。这是必需的,因为 java 代理只能与接口一起使用。代理使用附加(字节)代码来扩充类。

编辑:插件通常提供额外的功能来定义和检查切点和连接点。

Aspect-J uses an agent to modify the classes by so called load-time-weaving. This is required since java-proxies can only work with interfaces. The agent augments the classes with additional (byte) code.

EDIT: Plugins usually provide additional functionality to define and review point cuts and join points.

从此见与不见 2024-12-26 17:49:58

不,您不需要任何插件来编译/运行使用 AOP 编写的代码。

相反,您需要在编译/运行应用程序时添加类路径信息。

例如,您可以查看此处 。它使用 ant 添加aspectj jar 来运行示例。并且它不需要任何插件来运行 AspectJ 代码。

关于插件& eclipse:这是为了让 eclipse 能够理解 AspectJ 代码,而不是混淆为无效的 java 代码。

No, You dont require any plugin to compile/run code written using AOP.

Rather you need to add class-path information while compiling/running your application.

For example, you can take a look here. It adds aspectj jars using ant to run the example. And it needs no plugin to run the AspectJ code for sure.

About plugin & eclipse: This is about giving eclipse idea to understand AspectJ code and not to confuse as invalid java code.

所谓喜欢 2024-12-26 17:49:58

如果您有一个 Maven 项目,则只需添加一些依赖项即可与 Aspect 一起使用。
我正在使用 Netbeans 并使用 AspectJ,它运行得很好。无需安装插件。

请参阅:http://mojo.codehaus.org/aspectj-maven-plugin/获取一些信息。

If you have a Maven project, you just have to put some dependencies to work with Aspect.
I'm working with Netbeans and use AspectJ and it works perfectly. No plugin to install.

See : http://mojo.codehaus.org/aspectj-maven-plugin/ for some information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文