Skip to content

Forking JMH may fail on Windows with "CreateProcess error=206, The filename or extension is too long" #241

@piotrp

Description

@piotrp

It would be great if sbt-jmh included a workaround for running with long classpaths on Windows.
Currently JMH is failing to fork benchmarks and prints:

<failed to invoke the VM, caught IOException: Cannot run program "C:\Program Files\Java\...\java.exe": 
CreateProcess error=206, The filename or extension is too long>

This can be worked around by adding this to my sbt configuration:

    Jmh / run / javaOptions ++= (
      if (System.getProperty("os.name").startsWith("Windows")) {
        Seq("-Djmh.separateClasspathJAR=true", "\"-Djava.io.tmpdir=" + target.value + "\"")
      } else
        Seq.empty
      ),

-Djmh.separateClasspathJAR=true tells JMH to package classpath into JAR file. Setting -Djava.io.tmpdir= is required if source files aren't on the same drive as temp directory - https://github.com/openjdk/jmh/blob/1.37/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java#L874.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions