解决 idea 运行时报错:Command line is too long. Shorten command line for xxxTest.xxx or also for JUnit default configuration

发布时间:2024-08-09 15:17:07 作者:yexindonglai@163.com 阅读(172)

一、运行测试类或者main 函数时报错以下信息

  1. Error running 'PolicyServiceTest.getLatestPolicyInfoTest': Command line is too long. Shorten command line for PolicyServiceTest.getLatestPolicyInfoTest or also for JUnit default configuration

原因

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

二、处理方式

方法一:修改idea配置

直接修改 Shorten command line, 将其设置为Jar mainfest 或者classpath file点击 apply 即可

方法二:修改工作空间

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

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

关键字idea

上一篇: clion集成ffmpeg

下一篇: 没有了