Administrator
发布于 2023-12-18 / 42 阅读
0
0

IDEA启动失败,提示”Command line is too long“的原因及解决办法

前言

github 上 fork 了一份代码在本地 idea 上运行,点击运行,报错提示”Command line is too long. Shorten command line for Application or also for Spring Boot default configuration.“。网上搜寻到原因和解决方法,特此记录。

参考文章:https://blog.csdn.net/liuyaokai1990/article/details/118509142

原因

启动类 — run application,执行的命令太长了。一般来说是 classpath 命令后面接的jar包 太多了,超出系统(Windows:32767)所允许的命令长度。

D:\develop\jdk\jdk11\bin\java.exe ... -classpath ...

解决方法(2种)

1、修改工程下 ./idea/workspace.xml

此方法通用,但是仅推荐 2017.3 之前的版本使用,2017.3 之前的版本也只能使用这个方法。之后的版本看方法 2。

项目下 .idea\workspace.xml,找到标签 <component name="PropertiesComponent">。在标签里加一行:

<property name="dynamic.classpath" value="true" />

2、Shorten command line(异常提示有提到的,后面简称 scl)

1、右上角 run / debug configurations 下拉框(▶左边)

2、不同版本 scl 位置不同:

老版本(我的是2019.3):Edit Configurations > Environment > scl

2021之后版本:Edit Configuratioin >( scl 或者 Modify Options > scl )

3、弹出一行 Shorten command line 下拉框,默认是 none,选择 JAR manifest 或者 @argFiles(版本不同,选项可能不同,可能是 classpath file),保存即可。

结果

选择 scl 中的 @argFiles 后重新启动,可以正常启动。控制台首行的启动命令如下。

D:\develop\jdk\jdk11\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.profiles.active=dev,win -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:D:\develop\IntelliJ IDEA 2019.3.1\lib\idea_rt.jar=61048:D:\develop\IntelliJ IDEA 2019.3.1\bin" -Dfile.encoding=UTF-8 @C:\Users\gavin\AppData\Local\Temp\idea_arg_file424949821 run.halo.app.Application

可以看见,命令中有一个临时文件idea_arg_file424949821。打开一看,正是-classpath 引入依赖 jar 包的命令,编辑器提示有 37867 个字符,这也印证了上面提到的超出系统命令长度的说法。

D:\develop\gradle-6.8.3\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-json\2.5.12\549b45bb8d9edefb693406cc7e6c590943009cd8\spring-boot-starter-json-2.5.12.jar

上面是其中一个 jar 包地址,足足有 186 个字符,其他 jar 包地址差不多,有 232 个 jar 包。


评论