IDEA 10.5 命令行太长
在 Maven 项目中,当我运行测试用例时(在 Windows 上):
运行 TestApp.readParameter 时出错:命令行太长。在 为了减少其长度,可以使用类路径文件。你愿意吗 为您的所有运行配置启用类路径文件模式 项目?启用
set .iws
<property name="dynamic.classpath" value="true" />
如何修复此问题?
In Maven project when I run test case (on Windows):
Error running TestApp.readParameter: Command line is too long. In
order to reduce its length classpath file can be used. Would you like
to enable classpath file mode for all run configurations of your
project? Enable
set .iws
<property name="dynamic.classpath" value="true" />
How this could be fixed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
在 Intellij 中,转到“编辑配置”(运行 -> 编辑配置),在“缩短命令行”行中出现的配置选项卡中选择选项“classpath file”/“@argFiles (Java 9+)”,下拉菜单中的最后一个选项。为我修好了。
In Intellij, go to "edit configurations" (Run -> Edit Configurations), in the configuration tab that comes up in the line "shorten command line" select option "classpath file"/"@argFiles (Java 9+)", last option in the drop down menu. Fixed it for me.
在运行/调试配置中设置
缩短命令行:JAR 清单
可解决该问题。Setting the
Shorten command line:JAR manifest
in Run/Debug Configurations resolves the issue.从项目根文件夹中打开文件.idea/workspace.xml,转到部分
并添加以下内容:
Open the file .idea/workspace.xml file from your project root folder, go to section
and add the following:
在 Intelij 社区 2021.1 Windows 上执行此操作,工作正常:)
Did this on Intelij community 2021.1 windows, Worked fine :)
请参阅 dynamic.classpath 标志有什么作用? (IntelliJ 项目设置)。
不确定你想修复什么。如果需要避免动态类路径,请修改依赖项,将库、项目文件和 JDK 移动到短路径目录。
编辑:您在注释中链接的错误是有道理的,但是,即使使用动态类路径,运行测试时的命令行也会超出操作系统限制。发生这种情况是因为 IDEA 无法缩短大量命令行参数或选项,因为 IDEA 只能解决长类路径问题。我们对此无能为力,您应该修改将参数传递给应用程序的方式,以使命令行长度在限制之内。
从IDEA方面来说,我们会改进这种情况的处理。当已使用动态类路径时,将不再显示此对话框,并且您将收到另一条有关长命令行的错误消息。我已针对此案例提交了一个新问题。
See What does the dynamic.classpath flag do? (IntelliJ project settings).
Not sure what you want to fix. If you need to avoid dynamic classpath, revise your dependencies, move libraries, project files and JDK to a directory with short path.
Edit: the bug you linked in comments makes sense, however what happens is that the command line when running your tests exceeds the OS limit even when using dynamic classpath. This can happen because of lots of command line arguments or options which cannot be shortened by IDEA, as IDEA can only workaround long classpath issue. There is nothing we can do about it, you should revise the way you pass parameters to your app so that the command line length is within limits.
From the IDEA side, we'll improve the handling of such case. This dialog will no longer be displayed when dynamic classpath is already used and you will get another error message about the long command line. I've submitted a new issue for this case.
这解决了我的问题 - IntelliJ Idea版本 - 2022.2.3(终极版)
Run >编辑配置
修改选项>缩短命令行
选择 JAR 清单
This solved the problem for me on - IntelliJ Idea version - 2022.2.3 (ultimate edition)
Run > Edit Configurations
Modify Options > Shorten command line
Select JAR Manifest
就我而言,修复方法是更新
运行/调试配置
并在缩短命令行
中选择下一个选项类路径文件
。In my case fix was to update
Run/Debug Configurations
and select inShorten command line
the next optionclasspath file
.这是使用 Intelli J。我按照以下步骤操作,并且能够运行我的测试。
选项。
它解决了我。
This is with Intelli J. I followed the below steps and i am able to run my tests.
option.
It solved me.
我在这个错误上挣扎了很长时间,其他答案都没有帮助。
解决该问题的方法是将以下行添加到 Gradle 中的
pitest
配置中:useClasspathFile = true
现在是
build.gradle
文件有这样一个条目:这是链接到帖子对我有帮助。
I was struggling with this error for a long time and none of the other answered helped.
The thing that solved the issue was adding the following line to the
pitest
configuration in the Gradle:useClasspathFile = true
So now the
build.gradle
file has such an entry:Here is the link to the post that helped me.
答案中提到的选项在我使用的版本 2020.2 中不可用。我单击消息中显示的“启用”链接,这为我解决了这个问题。
The options mentioned in the answers aren't available in the version I'm using, 2020.2. I clicked on the "Enable" link shown in the message, and that fixed this issue for me.
转到应用程序配置和修改设置,如下
Go to The Application Configuration and Modified setting as below
在 Windows 机器上,我在尝试运行某个单元测试时遇到了这个问题。虽然 Maven 构建一切正常,而且我的同事也没有出现任何问题。
因为这是一个遗留项目,在反射和资源加载方面做了很多事情。
Shorten 命令并没有通过使用 argfile 来帮助我。
我收到此错误:
在运行配置中,当我将缩短命令行更改为 JAR Manifest 时,应用程序试图启动,但无法从类路径中找到某些资源。
解决方案
您可能有太多依赖项,导致命令行命令太长。每个依赖项都通过其绝对路径添加为类路径参数。因此,如果您的用户名很长,您的 .m2 路径将如下所示:
C:\Users\LastnameFirstname\.m2\repository
我通过移动我的
.m2\repository
解决了这个问题> 到C:\.m2\r
。更改了我的
C:\Users\\.m2\settings.xml
中的本地存储库路径在 IntelliJ Maven 设置中验证您的 Maven 存储库。
On a Windows machine I had this problem when trying to run a certain unit test. While everything worked fine with a Maven build and also my colleagues had no problems.
Since this is a legacy project doing much stuff with reflection and resource loading.
Shorten command did not help me by using an argfile.
I was getting this error:
In the run configuration when I changed shorten commandline to JAR Manifest the application was trying to start but could not find certain resources from the classpath.
Solution
You might have too many dependencies causing a commandline command which is too long. Every dependency is added as classpath argument by it's absolute path. So if you have a long username your .m2 path will look like this:
C:\Users\LastnameFirstname\.m2\repository
I solved it by moving my
.m2\repository
toC:\.m2\r
.Changed the local repository path in my
C:\Users\<name>\.m2\settings.xml
Verify your maven repository in IntelliJ Maven settings.
我也遇到了这个问题,解决方法是在注意到大量测试依赖项位于类路径上后添加skipTests标志;
I was also having this problem and the fix was to add the skipTests flag after noticing a lot of the test dependencies were on the class path;
我在使用社区版本时遇到了这个问题。
我通过使用 Maven 配置运行项目来解决这个问题。
I had this problem using the community version.
I managed the problem by running the project with the Maven configuration.