IDEA 10.5 Command line is too long
Asked Answered
R

14

164

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?

Rancidity answered 17/6, 2011 at 4:4 Comment(1)
Does this answer your question? How to configure "Shorten command line" method for whole project in IntelliJReinforce
A
335

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.

Anders answered 14/6, 2018 at 12:1 Comment(9)
if one makes a global junit config with same settings then it wont be necessary to do this setting for all individual test config one is running!Anders
To reach it from Intellij Top menu use "Run => Edit Configurations"Rosinarosinante
This doesnt look to be available anymore on the last Idea 2020.3Comity
I'm running IntelliJ IDEA Ultimate 2020.3. This option was available (and solved the problem for me).Rutherfordium
@Comity the option is there in 2020.3: Edit Configurations -> "Configurations" tab -> EnvironmentsFantastic
If you don't see option "Shorten command line", click on "Modify Options" and check "Shorten command line"Clichy
The fix also worked for me, but on WINDOWS the intellij had problems with picking up any updates to the code. So I reduced the length of the path of the repository C:/user/repository/lots-of-other-characters-and-sub-paths to C:/user/repository/not-so-many-of-other-characters-and-sub-paths. By leveraging that solution the "Shorten command" option was no longer needed and now the changes are properly taken into consideration by the IDEThornton
It still works on the 2022.1.2. Just the path is a little bit different. You need to "Modify options" near the title "Build and run".Disparage
The entire path Run > Edit Configurations > "shorten command line" works for me, except that instead of "classpath file" I needed "JAR manifest" (otherwise some XML resource files would not be found). IntelliJ IDEA 2022.1.1 CEDarbie
O
93

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

enter image description here

Offshoot answered 24/6, 2020 at 8:36 Comment(2)
If you don't see this option in the menu press "Modify options v Alt+M" dropdown menu and check "Shorten command line" option to show it (IDEA CE 2020.3).Rosado
"JAR manifest" (instead of Classpath) is what worked for me. IntelliJ IDEA 2022.1.1 CEDarbie
I
56

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" />
Interstratify answered 3/7, 2020 at 17:8 Comment(3)
Thanks for the details this really works tried and tested some bug in intellij i guess not picking correctly this helps.Contaminant
Best answer! This helps because it is a one time configuration. The "JAR manifest" solution on "Run > Configurations" is needed for every test you want to run and that is is not cool.Marque
for intellij 2022 : "dynamic.classpath": "true" inside the propertiesComponent stringApproximate
E
32

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

Ethelethelbert answered 27/9, 2021 at 15:10 Comment(0)
S
11

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.

Scuppernong answered 17/6, 2011 at 4:9 Comment(4)
i see it.when i set dynamic.classpath=true,the Command line is still too longRancidity
In this case it's a bug which should be reported at youtrack.jetbrains.net/issues/IDEA.Scuppernong
Now you can set "Shorten command line" to "JAR manifest" under your default JUnit configuration.Damle
I have not seen this in Linux (or it might have to do with Java 9). However I do not start to do refactoring of the project. More precise I am not allowed to. Do you have any other advice?Randellrandene
C
1

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

Catling answered 4/8, 2021 at 11:19 Comment(0)
S
1

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.

Suburbanize answered 26/11, 2021 at 6:54 Comment(0)
M
1

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.

Mencius answered 16/1, 2022 at 11:42 Comment(0)
K
1

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

Kaiserism answered 24/2, 2023 at 0:13 Comment(1)
Fixed it for me, thanks.Prithee
D
0

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.

Dissuasive answered 28/6, 2021 at 19:23 Comment(0)
P
0

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
Peroneus answered 26/2, 2022 at 13:54 Comment(0)
J
0

Go to The Application Configuration and Modified setting as below

enter image description here

Jakie answered 6/4, 2023 at 6:44 Comment(0)
K
0

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.

Koo answered 28/3 at 19:28 Comment(0)
L
-2

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

Lammas answered 9/11, 2020 at 21:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.