简体   繁体   中英

adding aspectJ jar in maven project

I created the AspectJ/maven project1 which can generate logs for particular methods. Maven created a .jar file which I added to maven project2. The problem is that project2 doesn't seem to 'see' it because there are no logs. When I put my aspectJ class to project2 manually everything works fine.

Should I add any dependencies in POM? Or something else?

Edit 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. The aspect library is part of the configuration of the Maven plugin for AspectJ. Your pom.xml doesn't seem to configure the aspectj-maven-plugin at all.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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