Java JMH找不到资源:/META-INF/BenchmarkList
我无法在eclipse中运行简单的JMH基准测试。 Maven依赖项:Java JMH找不到资源:/META-INF/BenchmarkList,java,eclipse,maven,jmh,Java,Eclipse,Maven,Jmh,我无法在eclipse中运行简单的JMH基准测试。 Maven依赖项: <dependency> <groupId>org.openjdk.jmh</groupId> <artifactId>jmh-core</artifactId> <version>1.12</version> </dependenc
<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>
运行结果:
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();
}
}
线程“main”java.lang.RuntimeException中出现异常:错误:无法
要查找资源:/META-INF/BenchmarkList
org.openjdk.jmh.runner.AbstractResourceReader.getReaders(AbstractResourceReader.java:96)
位于org.openjdk.jmh.runner.BenchmarkList.find(BenchmarkList.java:104)
位于org.openjdk.jmh.runner.runner.internalRun(runner.java:256)
org.openjdk.jmh.runner.runner.run(runner.java:206)位于
main(BTest.java:24)
也许问题是,我在eclipse上运行它 终于发现了。
缺少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>
org.codehaus.mojo
execmaven插件
运行基准测试
集成测试
执行官
测试
JAVA
-类路径
org.openjdk.jmh.Main
.*
我意识到,正如预期答案中提到的,我的父pom中已经有了exec-maven插件
,但我必须运行mvn-clean-install
,如中所述,以修复出现相同错误的错误;而从maven或intellij运行测试是行不通的。我意识到问题在于我用Kotlin编写了基准测试。将代码更改为java解决了这个问题。当编译器插件没有处理与JMH相关的注释时,可能会发生这种情况。对我来说,使用maven编译器插件
的
更新工作正常。pom.xml必须对Java微基准测试工具(JMH)框架具有以下依赖项和配置
<properties>
<jmh.version>1.21</jmh.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>java-jmh</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</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>
</plugins>
1.21
org.openjdk.jmh
jmh核
${jmh.version}
org.openjdk.jmh
jmh发生器
${jmh.version}
朱尼特
朱尼特
4.11
测试
JavaJMH
org.apache.maven.plugins
maven编译器插件
1.8
1.8
org.openjdk.jmh
jmh发生器
${jmh.version}
org.codehaus.mojo
execmaven插件
运行基准测试
集成测试
执行官
测试
JAVA
-类路径
org.openjdk.jmh.Main
.*
在此之后,转到命令行并运行命令$mvn clean install您是否尝试过在eclipse中不运行它?既然你提到了,那就试试看吧it@WillBarnwell还没有。。。这可能是对IDEA的一个回答。首先,对于Scala+Maven,我必须添加此项,以获得上面的错误…: