158

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?

Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
qinmiao
  • 5,559
  • 5
  • 36
  • 39
  • 1
    Does this answer your question? [How to configure "Shorten command line" method for whole project in IntelliJ](https://stackoverflow.com/questions/47926382/how-to-configure-shorten-command-line-method-for-whole-project-in-intellij) – Maulzey Feb 10 '20 at 23:00

14 Answers14

327

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.

Kevin Crum
  • 195
  • 2
  • 16
user7023213
  • 3,460
  • 2
  • 11
  • 15
  • 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! – user7023213 Nov 27 '18 at 12:06
  • 16
    To reach it from Intellij Top menu use "Run => Edit Configurations" – Vijai Nov 15 '19 at 17:13
  • 8
    This doesnt look to be available anymore on the last Idea 2020.3 – elect Jan 18 '21 at 15:19
  • 3
    I'm running IntelliJ IDEA Ultimate 2020.3. This option was available (and solved the problem for me). – Nathan Mar 02 '21 at 21:37
  • @elect the option is there in 2020.3: Edit Configurations -> "Configurations" tab -> Environments – Boommeister Mar 03 '21 at 19:21
  • 24
    If you don't see option "Shorten command line", click on "Modify Options" and check "Shorten command line" – cnmuc Apr 19 '21 at 13:01
  • 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 IDE – Radek Konrad Furmański Mar 15 '22 at 14:40
  • 1
    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". – rios0rios0 Jun 03 '22 at 14:55
  • 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 CE – datsb Jun 07 '22 at 06:22
89

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

enter image description here

techmagister
  • 1,188
  • 8
  • 14
  • 7
    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). – simno Dec 10 '20 at 16:24
  • 1
    "JAR manifest" (instead of Classpath) is what worked for me. IntelliJ IDEA 2022.1.1 CE – datsb Jun 07 '22 at 06:25
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" />
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Mamad Dansoko
  • 561
  • 4
  • 3
  • Thanks for the details this really works tried and tested some bug in intellij i guess not picking correctly this helps. – Doogle Nov 09 '20 at 05:44
  • 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. – Juliano Suman Curti Aug 22 '22 at 12:30
  • 1
    for intellij 2022 : "dynamic.classpath": "true" inside the propertiesComponent string – burdk Nov 30 '22 at 03:55
30

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

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.

Community
  • 1
  • 1
CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • i see it.when i set dynamic.classpath=true,the Command line is still too long – qinmiao Jun 17 '11 at 04:22
  • In this case it's a bug which should be reported at http://youtrack.jetbrains.net/issues/IDEA. – CrazyCoder Jun 17 '11 at 04:23
  • Now you can set "Shorten command line" to "JAR manifest" under your default JUnit configuration. – thijsraets Dec 14 '17 at 14:11
  • 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? – patrik Mar 21 '18 at 14:29
4

enter image description here

i set Shorten command line from none => JAR mainfest and it work, hope userful

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

Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
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.

GvSharma
  • 2,632
  • 1
  • 24
  • 30
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.

riorio
  • 6,500
  • 7
  • 47
  • 100
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.

user2233706
  • 6,148
  • 5
  • 44
  • 86
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
0

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

P.D
  • 141
  • 4
  • 14
0

Go to The Application Configuration and Modified setting as below

enter image description here

-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

user4157124
  • 2,809
  • 13
  • 27
  • 42