区块链技术博客
www.b2bchain.cn

错误:找不到或加载主类org.openjdk.jmh.runner.ForkedMain – java程序员分享

本文介绍了错误:找不到或加载主类org.openjdk.jmh.runner.ForkedMain – java程序员分享,有助于帮助完成毕业设计以及求职,是一篇很好的资料。

对技术面试,学习经验等有一些体会,在此分享。

我正在通过春季启动应用程序使用jmh对一些方法进行基准测试。当我通过IDE运行它时,它为我提供了基准,但是当我将其与maven打包并通过CMD运行时,它给出了以下堆栈跟踪。

# Run progress: 0.00% complete, ETA 00:11:00 # Fork: 1 of 1 Error: Could not find or load main class org.openjdk.jmh.runner.ForkedMain <forked VM failed with exit code 1> <stdout last='20 lines'> </stdout> <stderr last='20 lines'> Error: Could not find or load main class org.openjdk.jmh.runner.ForkedMain </stderr>  Benchmark had encountered error, and fail on error was requested Exception in thread "main" java.lang.reflect.InvocationTargetException         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)         at java.lang.reflect.Method.invoke(Method.java:498)         at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)         at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)         at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)         at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) Caused by: org.openjdk.jmh.runner.RunnerException: Benchmark caught the exception         at org.openjdk.jmh.runner.Runner.runBenchmarks(Runner.java:578)         at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:320)         at org.openjdk.jmh.runner.Runner.run(Runner.java:209)         at com.test.statistics.metrics.DruidBenchmarkApplication.main(DruidBenchmarkApplication.java:56)         ... 8 more Caused by: org.openjdk.jmh.runner.BenchmarkException: Benchmark error         at org.openjdk.jmh.runner.Runner.doFork(Runner.java:771)         at org.openjdk.jmh.runner.Runner.runSeparate(Runner.java:663)         at org.openjdk.jmh.runner.Runner.runBenchmarks(Runner.java:561)         ... 11 more         Suppressed: java.lang.IllegalStateException: Forked VM failed with exit code 1                 ... 14 more     **POM.XML:**  <?xml version="1.0" encoding="UTF-8"?> <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>com.test.stats</groupId>     <artifactId>druid-metrics</artifactId>     <version>0.0.1-SNAPSHOT</version>     <packaging>jar</packaging>      <name>druid-metrics</name>     <description>Demo project for benchmarking druid</description>      <parent>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-parent</artifactId>         <version>2.0.4.RELEASE</version>         <relativePath/> <!-- lookup parent from repository -->     </parent>      <properties>         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>         <java.version>1.8</java.version>         <docker.image.prefix>druid-metrics</docker.image.prefix>         <jmh.version>1.21</jmh.version>     </properties>      <dependencies>         <dependency>             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-web</artifactId>         </dependency>         <dependency>             <groupId>org.apache.directory.studio</groupId>             <artifactId>org.apache.commons.io</artifactId>             <version>2.4</version>         </dependency>          <dependency>             <groupId>org.json</groupId>             <artifactId>json</artifactId>             <version>20080701</version>         </dependency>         <!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->         <dependency>             <groupId>commons-lang</groupId>             <artifactId>commons-lang</artifactId>             <version>2.6</version>         </dependency>          <dependency>             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-test</artifactId>             <scope>test</scope>         </dependency>         <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>             <scope>provided</scope>         </dependency>     </dependencies>      <build>         <plugins>             <plugin>                 <groupId>org.springframework.boot</groupId>                 <artifactId>spring-boot-maven-plugin</artifactId>             </plugin>              <plugin>                 <groupId>com.spotify</groupId>                 <artifactId>dockerfile-maven-plugin</artifactId>                 <version>1.3.4</version>                 <configuration>                     <repository>${docker.image.prefix}/${project.artifactId}</repository>                 </configuration>             </plugin>         </plugins>     </build>   </project> 

我尝试过通过大量论坛中的信息显式设置类路径,但这无助于通过cmd运行应用程序。任何帮助,将不胜感激。

谢谢!

参考方案

与Gradle + JMH具有相同的ClassNotFoundException,在最新版本(incompatibility bug)中已对此jmh-gradle-plugin >= 0.5.0进行了修复。这条建议很荒谬:尝试升级(或降级)并查看是否仍然存在。

当我写下面的代码时,编译器说 无法从ArrayList<String>转换为List<Comparable>private List<Comparable> get(){ return new ArrayList<String>(); } 但是当我用通配符编写返回类型时,代码会编译。private List&l…

鉴于: List<Integer> integers = new ArrayList<>(Arrays.asList( 10, 12 )); List<Optional<Integer>> optionalIntegers = Arrays.asList( Optional.of(5), Optional.em…

我正在为SCJP / OCPJP学习,并且遇到了一个对我来说很奇怪的示例问题。该示例代码实例化了两个通用集合:List<?> list = new ArrayList<?>(); List<? extends Object> list2 = new ArrayList<? extends Object>(); …

我对Java泛型如何处理继承/多态感到困惑。假设以下层次结构-动物(父母)狗-猫(儿童)因此,假设我有一个方法doSomething(List<Animal> animals)。根据继承和多态性的所有规则,我假设List<Dog>是List<Animal>,而List<Cat>是List<Animal&g…

假设我有以下课程:class A { int id; List<B> b; } class B { int id; } 我想在A.id到B.id的列表之间创建一个映射(Map<Integer, List<Integer>>,其中key = A.id,而List<Integer>对应于每个A的B.id字段的列表)…

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » 错误:找不到或加载主类org.openjdk.jmh.runner.ForkedMain – java程序员分享
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们