eclipse JMH 无法找到资源:/META-INF/BenchmarkList
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38056899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JMH Unable to find the resource: /META-INF/BenchmarkList
提问by riva
I'm not able to run simple JMH benchmark inside eclipse. Maven dependencies:
我无法在 eclipse 中运行简单的 JMH 基准测试。Maven 依赖项:
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.12</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.12</version>
</dependency>
Java code:
爪哇代码:
public class BTest {
@Benchmark
public void test() {
// todo
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(BTest.class.getSimpleName())
.build();
new Runner(opt).run();
}
}
Result of run:
运行结果:
Exception in thread "main" java.lang.RuntimeException: ERROR: Unable to find the resource: /META-INF/BenchmarkList at org.openjdk.jmh.runner.AbstractResourceReader.getReaders(AbstractResourceReader.java:96) at org.openjdk.jmh.runner.BenchmarkList.find(BenchmarkList.java:104) at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:256) at org.openjdk.jmh.runner.Runner.run(Runner.java:206) at com.test.BTest.main(BTest.java:24)
线程“main”中的异常 java.lang.RuntimeException:错误:无法在 org.openjdk.jmh.runner.AbstractResourceReader.getReaders(AbstractResourceReader.java:96) 处找到资源:/META-INF/BenchmarkList 在 org.openjdk。 jmh.runner.BenchmarkList.find(BenchmarkList.java:104) at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:256) at org.openjdk.jmh.runner.Runner.run(Runner.java: 206) 在 com.test.BTest.main(BTest.java:24)
Maybe the problem is, that I'm running it from eclipse.
也许问题是,我是从 eclipse 运行它的。
采纳答案by riva
Finally found it out.
There was a problem with missing exec-maven-plugin
plugin
终于发现了。缺少exec-maven-plugin
插件有问题
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>run-benchmarks</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>org.openjdk.jmh.Main</argument>
<argument>.*</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
回答by ankitkpd
I realized that I already had exec-maven-plugin
in my parent pom as mentioned in expected answer but I had to run mvn clean install
as mentioned in https://stackoverflow.com/a/40748670to fix the error
我意识到我已经exec-maven-plugin
在预期答案中提到了我的父 pom 中,但我必须mvn clean install
按照https://stackoverflow.com/a/40748670 中提到的那样运行来修复错误
回答by rahulkesharwani
This could happen when your compiler plugin has not processed the JMH related annotations. For me, Gill's answerwith the maven-compiler-plugin
's <annotationProcessorPaths>
update worked.
当您的编译器插件未处理 JMH 相关注释时,可能会发生这种情况。对我来说,吉尔对maven-compiler-plugin
's <annotationProcessorPaths>
update的回答有效。
回答by PeterK
Having had the same error; and running the tests from maven or intellij didn't work. I realised that the problem was that I wrote the benchmark in Kotlin. Changing the code to java sorted the issue.
有同样的错误;并从 maven 或 intellij 运行测试不起作用。我意识到问题在于我用 Kotlin 编写了基准测试。将代码更改为 java 对问题进行了排序。