IDEA 10.5 命令行太长

发布于 2024-11-15 18:17:53 字数 275 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

浅语花开 2024-11-22 18:17:53

在 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.

自由如风 2024-11-22 18:17:53

在运行/调试配置中设置缩短命令行:JAR 清单 可解决该问题。

输入图像描述这里

Setting the Shorten command line:JAR manifest in Run/Debug Configurations resolves the issue.

enter image description here

沙与沫 2024-11-22 18:17:53

从项目根文件夹中打开文件.idea/workspace.xml,转到部分

<component name="PropertiesComponent">

并添加以下内容:

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

Open the file .idea/workspace.xml file from your project root folder, go to section

<component name="PropertiesComponent">

and add the following:

<property name="dynamic.classpath" value="true" />
静谧幽蓝 2024-11-22 18:17:53

在 Intelij 社区 2021.1 Windows 上执行此操作,工作正常:)

  1. 在编辑配置菜单上,单击“修改选项”,

  1. 然后选择“缩短命令行”,

  1. 选择“JAR 清单”选项,应用并添加它。运行

输入图像此处描述

Did this on Intelij community 2021.1 windows, Worked fine :)

  1. On the edit configuration menu, click on modify options

  1. And then select Shorten command line

  1. Select JAR manifest option, apply & run

enter image description here

风筝有风,海豚有海 2024-11-22 18:17:53

请参阅 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.

や莫失莫忘 2024-11-22 18:17:53

这解决了我的问题 - 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

enter image description here

Select JAR Manifest

enter image description here

挽袖吟 2024-11-22 18:17:53

就我而言,修复方法是更新运行/调试配置并在缩短命令行中选择下一个选项类路径文件
输入图片此处描述

In my case fix was to update Run/Debug Configurations and select in Shorten command line the next option classpath file.
enter image description here

笑脸一如从前 2024-11-22 18:17:53

这是使用 Intelli J。我按照以下步骤操作,并且能够运行我的测试。

  1. 转到编辑器顶部菜单的编辑配置。
  2. 在 JUnits => 下单击修改选项。
  3. java下=>选择“缩短命令”=>选择“JAR 清单
    选项。

它解决了我。

This is with Intelli J. I followed the below steps and i am able to run my tests.

  1. Go to Edit Configurations at the top menu of the editor.
  2. Under JUnits => click on modify Options.
  3. Under java => select "Shorten Command" => Select "JAR Manifest
    option.

It solved me.

南巷近海 2024-11-22 18:17:53

我在这个错误上挣扎了很长时间,其他答案都没有帮助。

解决该问题的方法是将以下行添加到 Gradle 中的 pitest 配置中:

useClasspathFile = true

现在是 build.gradle 文件有这样一个条目:

 pitest {
    threads = 4

    //adds dependency to org.pitest:pitest-junit5-plugin and sets "testPlugin" to "junit5"
    junit5PluginVersion = '0.12'

    useClasspathFile = true    <------------------------------

    targetClasses = ["com.example.service.*"]

    if (project.name in ['no-need-to-mutate-module']) {
        failWhenNoMutations = false
    }
}

这是链接到帖子对我有帮助。

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:

 pitest {
    threads = 4

    //adds dependency to org.pitest:pitest-junit5-plugin and sets "testPlugin" to "junit5"
    junit5PluginVersion = '0.12'

    useClasspathFile = true    <------------------------------

    targetClasses = ["com.example.service.*"]

    if (project.name in ['no-need-to-mutate-module']) {
        failWhenNoMutations = false
    }
}

Here is the link to the post that helped me.

┾廆蒐ゝ 2024-11-22 18:17:53

答案中提到的选项在我使用的版本 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.

陈甜 2024-11-22 18:17:53

转到应用程序配置和修改设置,如下

在此处输入图像描述

Go to The Application Configuration and Modified setting as below

enter image description here

も星光 2024-11-22 18:17:53

在 Windows 机器上,我在尝试运行某个单元测试时遇到了这个问题。虽然 Maven 构建一切正常,而且我的同事也没有出现任何问题。
因为这是一个遗留项目,在反射和资源加载方面做了很多事情。

Shorten 命令并没有通过使用 argfile 来帮助我。
我收到此错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/engine/TestDescriptor
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:375)
    at com.intellij.rt.junit.JUnitStarter.getAgentClass(JUnitStarter.java:241)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:222)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.TestDescriptor
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 5 more

在运行配置中,当我将缩短命令行更改为 JAR Manifest 时,应用程序试图启动,但无法从类路径中找到某些资源。

解决方案

您可能有太多依赖项,导致命令行命令太长。每个依赖项都通过其绝对路径添加为类路径参数。因此,如果您的用户名很长,您的 .m2 路径将如下所示:

C:\Users\LastnameFirstname\.m2\repository

我通过移动我的 .m2\repository 解决了这个问题> 到C:\.m2\r

更改了我的 C:\Users\\.m2\settings.xml 中的本地存储库路径

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

 <localRepository>C://.m2/r</localRepository>
...
</settings>

在 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:

Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/engine/TestDescriptor
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:375)
    at com.intellij.rt.junit.JUnitStarter.getAgentClass(JUnitStarter.java:241)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:222)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.TestDescriptor
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 5 more

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 to C:\.m2\r.

Changed the local repository path in my C:\Users\<name>\.m2\settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

 <localRepository>C://.m2/r</localRepository>
...
</settings>

Verify your maven repository in IntelliJ Maven settings.

嘿哥们儿 2024-11-22 18:17:53

我也遇到了这个问题,解决方法是在注意到大量测试依赖项位于类路径上后添加skipTests标志;

mvnw.cmd -DskipTests=true package

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;

mvnw.cmd -DskipTests=true package
無處可尋 2024-11-22 18:17:53

我在使用社区版本时遇到了这个问题。
我通过使用 Maven 配置运行项目来解决这个问题。

spring-boot:run -Dspring.profiles.active=local

Intellij Maven 配置

I had this problem using the community version.
I managed the problem by running the project with the Maven configuration.

spring-boot:run -Dspring.profiles.active=local

Intellij Maven Configuration

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文