Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
"

For the example I only let 3 jars but I have so many dependencies...

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

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

like image 699
Fundhor Avatar asked Mar 12 '19 14:03

Fundhor


People also ask

What is CLASSPATH in command line?

Classpath in Java is the path to the directory or list of the directory which is used by ClassLoaders to find and load classes in the Java program. Classpath can be specified using CLASSPATH environment variable which is case insensitive, -cp or -classpath command-line option or Class-Path attribute in manifest.

What is CP in Java command line?

Java -cp is a parameter in the Java Virtual Machine or Java compiler. The -cp, or CLASSPATH, is used as an option to the Java command. It is a parameter in the Java Virtual Machine or Java compiler that specifies the location of classes and packages which are defined by the user.

How do you fix command line is too long shorten command line in Intellij idea?

In Intellij, go to "edit configurations" (Run -> Edit Configurations), in the configuration tab that comes up in the line "shorten command line" select option "classpath file"/"@argFiles (Java 9+)", last option in the drop down menu. Fixed it for me.

How resolve shorten command line in Intellij?

In the Run/Debug Configuration dialog, a new field appeared: Shorten command line. The new field allows you to choose the way the IDE will shorten the command line from a drop-down list: None: This is the default option. The IDE doesn't shorten the long classpath.


2 Answers

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.

like image 79
jon-hanson Avatar answered Sep 29 '22 00:09

jon-hanson


If you are using Windows 10 Anniversary Update or Windows Server 2016, or later, you can increase the maximum path length beyond the 260 character default.

You can either copy the following two lines into a file with a .reg extension and open it,

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001

Or, open the Registry Editor and browse to the location, and change the value from 0 to 1.

like image 32
Strom Avatar answered Sep 28 '22 23:09

Strom