1

Maven project にアスペクトを追加する際に問題があります。小さなデモを用意しました:

Project1基本クラスを 1 つだけ含む

public class Sender {

    public static void main(String[] args) {
        System.out.println("here main");
    }
}

その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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Project1</groupId>
    <artifactId>Project1</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
    </properties>

    <build>

        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal><!-- to weave all your  main classes -->
                            <goal>test-compile</goal><!-- to weave all your test classes -->
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>Project2</groupId>
                            <artifactId>Project2</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
                </configuration>
            </plugin>

        </plugins>
    </build>


    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.6.11</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>Project2</groupId>
            <artifactId>Project2</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

    </dependencies>
</project>

次のProject21 つの側面が含まれます。

@Aspect
public class AspectL {

    @Pointcut("execution(* main(..))")
    public void defineEntryPoint() {
    }

    @Before("defineEntryPoint()")
    public void aaa(JoinPoint joinPoint) {
        System.out.println("aspect before");
    }

    @After("defineEntryPoint()")
    public void bbb(JoinPoint joinPoint) {
        System.out.println("aspect after");
    }
}

そしてそのpom

<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>Project2</groupId>
  <artifactId>Project2</artifactId>
  <version>0.0.1-SNAPSHOT</version>
<properties>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
  </properties>

  <build>

     <sourceDirectory>src</sourceDirectory>
    <plugins>
       <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.3</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal><!-- to weave all your main classes -->
              <goal>test-compile</goal><!-- to weave all your test classes -->
            </goals>
          </execution>
        </executions>
        <configuration>
          <source>${maven.compiler.source}</source>
          <target>${maven.compiler.target}</target>
        </configuration>
      </plugin>

    </plugins>
  </build>

  <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.6.11</version>
            <scope>compile</scope>
        </dependency>

  </dependencies>
</project>

しかし、結果、実行しようとするSender

Exception in thread "main" java.lang.NoSuchMethodError: AspectL.aspectOf()LAspectL;
    at Sender.main(Sender.java:6)

何かアドバイスはありますか?このプロジェクトを適切な方法で構成していますか? 大丈夫pomですか?どんな助けでも大歓迎です。

4

1 に答える 1

1

バージョンの競合があります: バージョン1.3のaspectj-maven-plugin AspectJバージョンを使用: 1.6.7

リンク v1.3

1.6.11 を使用する場合は、プラグイン バージョン 1.4 を使用できます。

リンク v1.4

于 2012-09-12T12:25:51.047 に答える