Search code examples
javamavencommand-lineclasspathmanifest.mf

Shorten classpath (-cp) for command line


My maven build in failing on jdeps plugin (we need it to upgrade to jdk11).

The command line is too long for windows. Here is the error I get:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jdeps-plugin:3.1.1:jdkinternals (default) on project myproject:
[ERROR] Exit code: 1 - La ligne de commande est trop longue.
[ERROR]
[ERROR] Command line was: cmd.exe /X /C 
"
    "C:\Program Files\Java\jdk-11.0.2\bin\jdeps.exe"
    -cp "
        C:\Users\Me\.m2\repository\com\something\firstJar.jar;
        C:\Users\Me\.m2\repository\com\somethingElse\secondJar.jar;
        C:\Users\Me\.m2\repository\com\somethingDifferent\someOtherJar.jar;
        ... and one more
        ... and another one
        ... I think you get the idea......."
    --multi-release 9 D:\git\myworkspace\myproject\target\classes
"

How to shorten this command-line? (and make sure it is not user dependant)

Restriction: It is a shared project, changing anything only on my computer is not a solution.


Solution

  • The maven-jdeps-plugin is using plexus-utils to fork out a child process to run the jdeps executable. plexus-utils implements this by building up a command-line and passing it to cmd.exe. This is the wrong approach as it will be subject to the 8192 char limit imposed by cmd.exe. The correct approach would be to use the Java ProcessBuilder API. This itself uses ProcessImpl.create API method, which, on Windows, is implemented by a Win32 API call to CreateProcess. The latter API has a 32k char limit, which should be enough for most use cases.

    There is a plexus-utils bug report for this. You may want to raise one with maven-jdeps-plugin as well - the Java ProcessBuilder API is quite usable, so there's no need to use plexus-utils just to run jdeps.