Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mvn spring-boot:run with classpaths that exceeds Windows' length limits #17766

Closed
pneuschwander opened this issue Aug 2, 2019 · 25 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@pneuschwander
Copy link

Hi there, we use Spring Boot Version 2.1.5.RELEASE + maven 3.6.0 on a windows 10 machine to develop a spring webmvc application.

When invoking mvn spring-boot:run the following exception occurs:

Caused by: java.io.IOException: CreateProcess error=206, The filename or extension is too long
    at java.lang.ProcessImpl.create (Native Method)
    at java.lang.ProcessImpl.<init> (ProcessImpl.java:420)
    at java.lang.ProcessImpl.start (ProcessImpl.java:151)
    at java.lang.ProcessBuilder.start (ProcessBuilder.java:1107)
    at java.lang.ProcessBuilder.start (ProcessBuilder.java:1071)
    at org.springframework.boot.loader.tools.RunProcess.run (RunProcess.java:81)
    at org.springframework.boot.maven.RunMojo.forkJvm (RunMojo.java:103)

Problem: Our classpath is too long as we have many dependencies.

A feature/fix to shorten the command line in such cases (e.g. use of temp argFile) would be awesome.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 2, 2019
@philwebb
Copy link
Member

philwebb commented Aug 2, 2019

Out of interest, have you tried this: https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/

@philwebb philwebb added the status: waiting-for-feedback We need additional information before we can continue label Aug 2, 2019
@pneuschwander
Copy link
Author

@philwebb Thank you for that hint. I tried it but sadly it does not work in this case. Still getting the same exception :-/

Maybe it is not about the filepath length limit.
java.lang.ProcessImpl.create javadoc states "Create a process using the win32 function CreateProcess."
Found these information sources:

stating that the command line length is limited to 32767 characters.
Our classpath exceeds this limit as there are too many entries...

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 4, 2019
@philwebb
Copy link
Member

philwebb commented Aug 5, 2019

Thanks for trying, we'll have to try and investigate what options we have.

@philwebb philwebb added type: bug A general bug and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Aug 5, 2019
@philwebb philwebb added this to the 2.1.x milestone Aug 5, 2019
@wilkinsona
Copy link
Member

I believe ./gradlew bootRun will also be affected.

There's some interesting discussion of this in a couple of Gradle issues: gradle/gradle#1989 and gradle/gradle#10114. A pathing jar (jar that's used purely to declare the classpath via its manifest) is the most common solution but those issues point out some notable downsides. The latter of the two is tracking a fix for the problem that would mean we don't need to do anything on the Gradle side when using Gradle 6+.

@koosty
Copy link

koosty commented Oct 31, 2019

I have the same issue with 2.2.0.RELEASE but works fine with 2.1.9.RELEASE.
I'm using Windows 10 and tested both with Maven 3.5.0 and 3.6.0

@rampem
Copy link

rampem commented Nov 13, 2019

I have similar issue with 2.2.0.RELEASE and 2.2.1.RELEASE while 2.1.10.RELEASE works fine. It could be the classpath which in my case is around 37500 characters.

@bjornmagnusson
Copy link

bjornmagnusson commented Nov 28, 2019

We are also experiencing this issue when upgrading to 2.2.0.RELEASE.
Worked fine in 2.1.2.RELEASE

Discovered our classpath was roughly 38000 characters long

The work-around we took was moving the USER_HOME/.m2/repository to C:/m2

@wilkinsona
Copy link
Member

wilkinsona commented Nov 28, 2019

For those experiencing the problem on update, I would guess that there's now an extra transitive dependency or some version numbers have gained an extra digit and this has been enough to cause the length of the classpath to exceed Windows' limits. You may want to compare the old classpath with the new to identity where the extra length has been introduced.

@Jeevamanivel-tech
Copy link

We are experiencing same issue with Spring Boot 1.5.13.RELEASE, Maven 3.6.3. Please throw some light on this.
Tried following workarounds, none of them fixes the issue.

  1. Moved m2 repository from USER_HOME/.m2/repository to D:/m2
  2. maven-jar-plugin : manifest : addClassPath : true - Its adding all the jar path to manifest file. But doesn't fix the issue

@rekhubs
Copy link

rekhubs commented Apr 7, 2020

We are experiencing same issue with Spring Boot 1.5.13.RELEASE, Maven 3.6.3. Please throw some light on this.
Tried following workarounds, none of them fixes the issue.

  1. Moved m2 repository from USER_HOME/.m2/repository to D:/m2
  2. maven-jar-plugin : manifest : addClassPath : true - Its adding all the jar path to manifest file. But doesn't fix the issue

this works for me:
https://stackoverflow.com/a/54246754/2893542

@JavaWebinar
Copy link

Forking is enabled by default since Spring Boot 2.2.
See https://stackoverflow.com/questions/61125404/since-2-2-0-spring-boot-maven-plugin-create-2-java-process-may-cause-createproc question and solution

@wilkinsona wilkinsona changed the title mvn spring-boot:run + large classpath = filename is too long Support mvn spring-boot:run with classpaths that exceeds Windows' length limits Jun 8, 2020
@wilkinsona wilkinsona added type: enhancement A general enhancement and removed type: bug A general bug labels Jun 8, 2020
@wilkinsona wilkinsona modified the milestones: 2.1.x, 2.x Jun 8, 2020
@H3llK33p3r
Copy link

Why not being able to customize the plugin to use a file classpath (@argfile) ? Intellij offers this possibility to shorten the size of the arguments.

@cquoss
Copy link

cquoss commented Dec 2, 2020

Wouldn't it be possible to switch the classpath from the command line (-cp) to the CLASSPATH environment variable? This would reduce the length of the command line drastically. I forked spring-boot to give this option a try.

@philwebb
Copy link
Member

philwebb commented Dec 2, 2020

@cquoss That might be an option, although I suspect it would work when the fork option is false

@cquoss
Copy link

cquoss commented Dec 2, 2020

Yeah. But why not have it work with fork, too?

@cquoss
Copy link

cquoss commented Jan 20, 2021

Well. My PR was rejected. I wanted to use CLASSPATH env var instead of -cp command line option.

You mentioned something of a better solution being using the Classpath entry in MANIFEST.MF of a dedicated classpath-only jar. But how is this activated when using spring-boot:run Maven goal on the Windows command line? How has the POM file to be changed to use this? Please advise.

Please note: My solution would have worked out-of-the-box. No changes in POM etc. needed.

@philwebb
Copy link
Member

@cquoss There's currently no way configure the POM file to use a pathing jar. We'd need to make changes to the code in order to support long paths.

@cquoss
Copy link

cquoss commented Jan 21, 2021

Well then. Looks like my solution goes into a customized spring-boot maven plugin, then, here at our site. We need a solution.

@WoodenAndrew
Copy link

Out of interest, have you tried this: https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/

Not applicable to Windows server 2012.

@boly38
Copy link

boly38 commented Mar 12, 2021

I would try a workaround description of what did work for us

@regmebaby sources states that

command line length is limited to 32767 characters.

In order to diagnose your classpath length, use mvn debug mode (ie. mvn -X spring-boot:run). check Classpath for forked process output.

To make shortest your classpath component (java home and .m2), you could use this @rekhubs sources tips (cmd.exe)

mklink /J C:\M C:\Users\boly38\.m2\repository
mklink /J C:\J C:\Tools\Java\java-1.8.0-openjdk-1.8.0.275-1.b01

Then try again(I'm using git bash)

JAVA_HOME=/C/J mvn -Dmaven.repo.local=/C/M spring-boot:run

Windows <3

@kterry
Copy link

kterry commented Mar 7, 2024

This has become more relevant for Spring Boot 3 since fork option has been removed from the Maven plugin. This issue is currently blocking the migration of our projects to Spring Boot 3. An option to generate a pathing jar as suggested above would be ideal, akin to Exec Maven Plugin's longClasspath option.

@wilkinsona wilkinsona added the for: team-meeting An issue we'd like to discuss as a team to make progress label Mar 8, 2024
@tomekdski
Copy link

This thread is about spring-boot:run, but we also have a scenario for spring-boot:start
Solution implemented in spring-attic/spring-native#1585 looks great and would be a nice option.

@philwebb philwebb removed the for: team-meeting An issue we'd like to discuss as a team to make progress label Mar 18, 2024
@mhalbritter mhalbritter modified the milestones: 3.x, 3.3.0-M3 Mar 19, 2024
@mhalbritter
Copy link
Contributor

mhalbritter commented Mar 19, 2024

We're now using an argfile when running on Windows. I explored the avenue with the pathing JAR, however it was a lot more code (because we need to separate directories from JARs, because only JARs can go in the manifest) and other funny stuff. The argfile change is pretty minimal.

@liudongmiao

This comment was marked as outdated.

@philwebb

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests