使用perf4j与aspectj时出错(NoSuchMethodError)

时间:2014-02-04 15:45:59

标签: maven aspectj perf4j onejar aspectj-maven-plugin

我尝试将CTW与aspectj配合使用perf4j来分析我的应用程序(cumulusrdf)。

我可以用maven编译所有内容。控制台输出包含I< m;用于使分析工作的方法的条目:

[INFO] --- aspectj-maven-plugin:1.5:compile (default-cli) @ cumulusrdf ---
[INFO] Join point 'method-execution(void edu.kit.aifb.cumulus.store.AbstractCassandraRdfHector.bulkLoad(java.io.File, java.lang.String, int))' in Type 'edu.kit.aifb.cumulus.store.AbstractCassandraRdfHector' (AbstractCassandraRdfHector.java:373) advised by around advice from 'org.perf4j.log4j.aop.TimingAspect' (perf4j-0.9.16-log4jonly.jar!AbstractTimingAspect.class(from AbstractTimingAspect.java))

我使用目标aspectj:compile package进行构建。当我尝试运行生成的one-jar时,我得到以下异常:

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at edu.kit.aifb.cumulus.cli.Main.main(Main.java:40)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.simontuffs.onejar.Boot.run(Boot.java:340)
        at com.simontuffs.onejar.Boot.main(Boot.java:166)
Caused by: java.lang.NoSuchMethodError: org.perf4j.log4j.aop.TimingAspect.aspectOf()Lorg/perf4j/log4j/aop/TimingAspect;
        at edu.kit.aifb.cumulus.store.AbstractCassandraRdfHector.bulkLoad(AbstractCassandraRdfHector.java:373)
        at edu.kit.aifb.cumulus.cli.Load.main(Load.java:161)
        ... 11 more

我不会使用任何参数,除了我申请的参数。

在我的pom.xml中,我有以下相关部分:

aspectj插件的定义:

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.5</version>

        <configuration>
            <aspectLibraries>
                <aspectLibrary>
                    <groupId>org.perf4j</groupId>
                    <artifactId>perf4j</artifactId>
                    <classifier>log4jonly</classifier>
                </aspectLibrary>
            </aspectLibraries>
            <source>1.6</source>
            <target>1.6</target>
            <complianceLevel>1.6</complianceLevel>
            <verbose>true</verbose>
            <showWeaveInfo>true</showWeaveInfo>
            <weaveMainSourceFolder>true</weaveMainSourceFolder>
        </configuration>

        <!--<executions>
            <execution>
                <goals>
                    <goal>compile</goal>       <! use this goal to weave all your main classes >
                </goals>
                <configuration>
                    <showWeaveInfo>true</showWeaveInfo>
                </configuration>
            </execution>
        </executions>-->
    </plugin>

    <!-- ... -->
</plugins>

相关工件的依赖关系:

<dependencies>
    <dependency>
        <groupId>org.perf4j</groupId>
        <artifactId>perf4j</artifactId>
        <version>0.9.16</version>
        <classifier>log4jonly</classifier>
    </dependency>
    <dependency>
        <groupId>org.perf4j</groupId>
        <artifactId>perf4j</artifactId>
        <version>0.9.16</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.7.3</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>1.7.3</version>
    </dependency>
    <dependency>
        <groupId>commons-jexl</groupId>
        <artifactId>commons-jexl</artifactId>
        <version>1.1</version>
    </dependency>

    <!-- ... -->
</dependencies>

one-jar插件的定义:

<plugins>
    <plugin>
        <groupId>org.dstovall</groupId>
        <artifactId>onejar-maven-plugin</artifactId>
        <version>1.4.4</version>
        <executions>
            <execution>
                <configuration>
                    <mainClass>edu.kit.aifb.cumulus.cli.Main</mainClass>
                    <onejarVersion>0.97</onejarVersion>
                    <attachToBuild>true</attachToBuild>
                    <classifier>onejar</classifier>
                </configuration>
                <goals>
                    <goal>one-jar</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

    <!-- ... -->
</plugins>

有人知道我做错了吗?

1 个答案:

答案 0 :(得分:1)

尝试

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.4</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <complianceLevel>1.6</complianceLevel>
        <verbose>true</verbose>
        <showWeaveInfo>true</showWeaveInfo>
        <weaveMainSourceFolder>true</weaveMainSourceFolder>                    

        <weaveDependencies>
            <dependency>
                <groupId>org.perf4j</groupId>
                <artifactId>perf4j</artifactId>
                <classifier>log4jonly</classifier>
            </dependency>
        </weaveDependencies>

    </configuration>
    <executions>
        <execution>
            <id>aspectj-compile</id>
            <goals>
                <goal>compile</goal>
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>