Intellij IDEA 运行报错 Command line is too long.shorten command line for xxx or also for Spring boot

发布于:2023-09-27 ⋅ 阅读:(96) ⋅ 点赞:(1)

一、引言

   在运行某个工程时,Intellij IDEA报错:Command line is too long.shorten command line for xxx or also for Spring boot default configuration?在这里插入图片描述
大家是否遇到过这种问题?

二、处理方式

方法一:修改idea配置

   直接修改Shorten command line,将其设置为Jar mainfest 或者classpath file点击apply即可
在这里插入图片描述
   有同学说,我这个配置界面没有Shorten command line怎么办?点击该页面右上角的Modify option后选择Shorten command line就会显示在配置界面,如下图
在这里插入图片描述
在这里插入图片描述

方法二:修改工作空间

   找到工程对应.idea文件夹中workspace.xml文件中<component name="PropertiesComponent">
标签,在后面增加< property name="dynamic.classpath" value="true" />配置。

原因探索

我们去jetbrains官网进行搜索,结果如下:在这里插入图片描述
   classpath有可能很长。如果不缩短的话,那么JVM启动命令有可能因为classpath太长导致超过了操作系统的允许的最长命令参数长度,从而导致启动失败。所以这里有3种方式可以来缩短classpath的长度,进而缩短JVM启动的参数。3种选项的意思如下:

  • none(默认):不缩短JVM参数,直接把所有classpath作为JVM参数穿进去
  • JAR manifest:把所有classpath写入到临时的claapath.jar包中的manifest文件中,在manifest文件的Class-Path属性中指定所有的classpath。然后JVM参数中指定classpath参数为claapath.jar所在的绝对路径
  • classpath file:把所有的classpath写入到临时的文本文件中,然后把classpath设置到idea自定义的URLClassLoader中,然后使用自定义的URLClassLoader加载程序入口,反射调用main方法。main方法所在的类的ClassLoader就是idea自定义的URLClassLoader
本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到