简体   繁体   English

在Maven项目中添加AspectJ jar

[英]adding aspectJ jar in maven project

I created the AspectJ/maven project1 which can generate logs for particular methods. 我创建了AspectJ / maven project1,它可以为特定方法生成日志。 Maven created a .jar file which I added to maven project2. Maven创建了一个.jar文件,我将其添加到了maven project2中。 The problem is that project2 doesn't seem to 'see' it because there are no logs. 问题在于project2似乎没有“看到”它,因为没有日志。 When I put my aspectJ class to project2 manually everything works fine. 当我将我的AspectJ类手动放入project2时,一切正常。

Should I add any dependencies in POM? 我应该在POM中添加任何依赖项吗? Or something else? 或者是其他东西?

Edit pom.xml: 编辑pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>AJDemo</groupId>
    <artifactId>AJDemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
        <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.6.8</version>
        </dependency>
    </dependencies>
</project>

You must include the maven module that contains your aspects as both a dependency and an aspect library in the pom.xml of every module in which you want your aspects to be applied. 您必须在要应用方面的每个模块的pom.xml中都包含同时包含方面和依赖库的maven模块。 The aspect library is part of the configuration of the Maven plugin for AspectJ. 方面库是用于AspectJ的Maven插件的配置的一部分。 Your pom.xml doesn't seem to configure the aspectj-maven-plugin at all. 您的pom.xml似乎根本没有配置AspectJ-Maven-plugin。

This page explains it and has an example, while this SO question has another good tip: if you want your aspects applied to every module of your project anyway, just put the necessary dependency and plugin config into the parent project's pom.xml. 该页面对此进行了解释,并提供了一个示例,而该SO问题还有另一个很好的提示:无论如何,如果要将方面应用于项目的每个模块,只需将必要的依赖项和插件配置放入父项目的pom.xml中即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM