Shorten classpath (-cp) for command line
Asked Answered
C

6

13

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.

Canaliculus answered 12/3, 2019 at 14:19 Comment(1)
Possible duplicate of #1068063Lacunar
P
6

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.

Parable answered 19/3, 2019 at 12:40 Comment(3)
@Canaliculus Do you mean you modified the maven-jdeps-plugin? Are you certain your build was using yuour build of the plugin and not still using the original?Parable
@Canaliculus can you post some code for your usage of the ProcessBuilder API?Parable
For the record, @jon-hanson was right, I did not make the changes correctly. This is the correct solution.Canaliculus
C
1

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.

Cluny answered 22/3, 2019 at 3:58 Comment(5)
Thanks Strom, that's a way to bypass the restriction, but it's for a shared project, I can't ask everyone to change its reg.Canaliculus
Not sure why, but this regkey was already set to 1 and I still get the error. Windows Server 2016Presidentelect
@JGlass, does your class path exceed the new limit? I suggest you to follow the accepted answers solution in addition to this this one.Cluny
@Strom, yeah it exceeds the limit, I will try out the accepted solution, thank you!Presidentelect
I think I already did this, this is not the solution to increase java classpath command line size.Merits
B
0

The best is to create empty jar file with classpath configured in manifest.

Official oracle document is at Adding Classes to the JAR File's Classpath

maven-jar plugin does support updating manifest classpath attribute: How to add Class-Path to the manifest file with maven

Breadth answered 21/3, 2019 at 10:25 Comment(0)
L
0

maybe a bit of a cheeky solution but...

what about using an env variable?

set MR=C:\Users\Me\.m2\repository\

"C:\Program Files\Java\jdk-11.0.2\bin\jdeps.exe"
    -cp "
        %MR%\com\something\firstJar.jar;
        %MR%\com\somethingElse\secondJar.jar;

did not test, hope it works...

Loam answered 21/3, 2019 at 18:33 Comment(0)
G
0

This is the reason Maven is meant to mange a large amount of dependency as you can simply place all of them in the .pom file. The use of the a centralized dependency list allows Maven to be able to see nearly everything you need to run your program. Take a look at this post that does what you're trying though add each of your jar's for Maven to see them. How do I package and run a simple command-line application with dependencies using maven?

Also, a good guide to the .pom basics Read the pom guide on www.maven.apache.org.

Maven will not use cmdline arguments the way you are trying because of the Manifest specifications. This is the fundamental reason programmers, including myself, love Maven so it will really make life much simpler as it's built to do exactly what you need. As the files change you have one file to make your updated versions.

Geniagenial answered 21/3, 2019 at 23:22 Comment(0)
D
0

So I did struggle with this problem for a long time and finally found solution to this issue with too long classpath while doing maven build. This is a workaround but it works perfectly.

Run build from linux - that't not a joke (sic!)

  • Turn on WSL(Windows Subsystem for Linux) on Windows by following https://learn.microsoft.com/en-us/windows/wsl/install-win10
  • After all done just Run your Linux subsystem on windows
  • edit linux maven settings.xml /usr/share/maven/conf/settings.xml
  • Add or override <localRepository>/mnt/c/.m2</localRepository> (/mnt/c/.m2) - is my windows maven repo path seen from WSL
  • cd /path/to/your/project
  • mvn build
Decimate answered 4/3, 2020 at 15:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.