解决Command line is too long. Shorten command line for xxx or also for Spring Boot default configurat

1. 复现错误


今天启动spring boot项目时,却出现如下错误:

在这里插入图片描述

Error running ‘Application’: Command line is too long. Shorten command line for SpringBootMainApplication or also for Spring Boot default configuration

2. 分析问题


Error running ‘Application’: Command line is too long. Shorten command line for SpringBootMainApplication or also for Spring Boot default configuration错误,翻译成中文,如下图所示:

在这里插入图片描述

通过翻译后的报错信息来看,可知是命令行太长的原因导致SpringBoot和整个应用无法成功启动,那为什么会报这样一个错误呢?

其实IDEA底层是通过命令行或者文件的方式将classpath传递到JavaJVM虚拟机上的,而大多数的操作系统都会有命令行的最大长度限制,超过这个限定值时就会导致IDEA无法启动当前程序。

当命令行长度大于32768个字符时,将IDEA切换到动态类路径。长类路径被写入文件,然后由应用程序启动器读取并通过系统类加载器加载。

3. 解决错误


既然知道了错误原因,便可按如下方式解决错误:

  1. 在项目中找到.idea文件夹,找到项目目录下的.idea\workspace.xml文件,如下图所示:

在这里插入图片描述

  1. 单击打开workspace.xml文件,使用Ctrl + F快捷键打开搜索栏。在搜索栏中输入PropertiesComponent,找到PropertiesComponent标签,如下图所示:

在这里插入图片描述

  1. PropertiesComponent标签栏内添加如下代码:
<property name="dynamic.classpath" value="true" />

在这里插入图片描述

该配置的主要功能就是开启IDEA的动态类路径,将太长的类路径写入文件,然后由应用程序启动器读取并通过系统类加载器加载

  1. 重新启动项目,即可启动成功

猜你喜欢

转载自blog.csdn.net/lvoelife/article/details/132980684
今日推荐