Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Could not find or load main class org.openjdk.jmh.runner.ForkedMain

I am benchmarking some methods using jmh through a spring boot application. When i run it through IDE it gives me benchmarks but when i package it with maven and run it through CMD it gives the below stack trace.

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

I have tried setting classpath explicitly through info from bunch of forums but that didn't help running the application through cmd. Any help would be appreciated.

Thanks!

like image 506
sn879 Avatar asked Aug 21 '18 15:08

sn879


1 Answers

Had same ClassNotFoundException with Gradle + JMH which was an incompatibility bug fixed in recent versions (jmh-gradle-plugin >= 0.5.0). As blase as this advice is: try upgrading (or downgrading) and seeing if it still occurs.

like image 142
drekbour Avatar answered Sep 28 '22 12:09

drekbour