【问题标题】:Error using perf4j with aspectj (NoSuchMethodError)将 perf4j 与 aspectj 一起使用时出错 (NoSuchMethodError)
【发布时间】:2014-02-04 15:45:59
【问题描述】:

我正在尝试将 CTW 与 aspectj 结合使用,通过 perf4j 分析我的应用程序 (cumulusrdf)。

我可以用 maven 编译一切就好了。控制台输出包含我用于使分析工作的方法的条目:

[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>

一罐插件的定义:

<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>

有人知道我做错了吗?

【问题讨论】:

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


    【解决方案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>
    

    【讨论】:

    • 有些人可能会问它是如何工作的,但它只是将缺少的类放入您的 jar 中的 org\perf4j\log4j\aop\ 中,因此这就是找到类的方式。
    猜你喜欢
    • 1970-01-01
    • 2021-10-12
    • 2023-03-13
    • 2020-04-12
    • 1970-01-01
    • 1970-01-01
    • 2014-08-16
    • 2015-08-08
    • 2016-11-05
    相关资源
    最近更新 更多