IntelliJ: Command Line is too Long. Shorten command line for... in SBT project

15,712

Solution 1

Found the fix, this is SBT specific. I believe what is happening is that the libaryDependencies one puts in their build.sbt file actually adds all the jars of those dependencies to the classpath used to run your program.

To fix this, simply add

lazy val scriptClasspath = Seq("*") (the lazy may be optional)

to your build.sbt file. I placed mine above the root val with the library dependencies. Not sure if that's necessary, but shift it around if you're having trouble

What this does, is upon running the program SBT will condense the "long" classpath built by those jars into a jar of its own, and just run that jar, which will kick off all of your dependencies and program.

Check this out for the longer demonstration, as well as other answers

Solution 2

This answer is based on IntelliJ 2020.1.4

  1. Open the configuration. This is usually found in the Debug/Run toolbar.
  2. You will find Shorten Command Line item in the Configuration dialog box. There are different modes that you can select there. In my case JAR Manifiest worked.

You can also set this as the default the next time you auto-generate a test.

enter image description here

Share:
15,712
NateH06
Author by

NateH06

Updated on June 14, 2022

Comments

  • NateH06
    NateH06 almost 2 years

    When I try to run my app, IntelliJ has just started to tell me

    "Command Line is too Long. Shorten command line for my_app or also for Application default configuration."

    the my_app is a blue link which leads to an "Edit Configuration" window, automatically selecting and highlighting a dropdown for class path shortener. I select the suggested options, but no change.

    I have no idea what this means - I'm using Scala, so I'm using a simple object MyObj extends App which takes no parameters at all.

    I have tried adding <property name="dynamic.classpath" value="true" /> to the workspace.xml as suggested by other similar questions, but to no avail.

    I used to be able to run my programs in my project fine before. But what lengthens a command line? What is being put on the command line at all?

  • Manabu Tokunaga
    Manabu Tokunaga almost 4 years
    Still did not work in my situation, but this is likely also due to the Windows CMD argument limitation. Would likely have worked in *nix environment.
  • Pedro García Medina
    Pedro García Medina over 3 years
    Incidentally, do you know why that happens? What does it mean that the command line be too long? and, what are we changing when that option is selected?. Thanks
  • Manabu Tokunaga
    Manabu Tokunaga over 3 years
    My guess, but Windows has a notorious limitation on the total number of characters in a command line of 2047 = 2K- 1 characters. IntelliJ and SBT often pack a bunch of ENV values in a command line. People used to Unix go without this limitation and this type of surprise happens when working with SBT on Windows.
  • Manabu Tokunaga
    Manabu Tokunaga over 2 years
    As of IntelliJ 2021.2.2 (or a bit earlier) IntelliJ will automatically fix this issue for you. Please check the warning/suggestion message the first time you launch your debugger.