问题:IDEA运行代码等时候报错:Error running xxxx. Command line is too long. Shorten the command line via JAR manifest or via a classpath file and rerun.
解答:其实IDEA已经给出解决方案了。修改IDEA的参数Shorten command line以缩短命令行,可以选择 JAR manifest 或者 a classpath file。使用 idea运行代码和实际上Linux运行代码的时候使用的类加载器不同,最好使用 none 或者 JAR mainfest 方式。
这篇博客写得风趣幽默,又分析了原因,请参考:
又一次被idea坑了(Shorten command line)
原因:
classpath有可能很长。如果不缩短的话,那么JVM启动命令有可能因为classpath太长导致超过了操作系统的允许的最长命令参数长度,从而导致启动失败。所以这里有3种方式可以来缩短classpath的长度,进而缩短JVM启动的参数。
Shorten command line的3种方式:
-
none:不会缩短classptah。如果命令行参数长度超过了操作系统的限制,那么idea就不会运行应用,然后会显示一个提示语来建议你缩短命令行长度
-
JAR manifest:idea会把classpath写入临时生成的classpath.jar中的manifest文件中
-
classpath file: idea将把一个长classpath写入一个文本文件