Early Access Program Features

IntelliJ IDEA: Configurable command line shortener

In IntelliJ IDEA, it’s possible to configure a command-line shortener. Let’s take a closer look at when and how to use this feature.

Configurable command line shortener

When the classpath gets too long, or you have many VM arguments, the program cannot be launched. The reason is that most operating systems have a command line length limitation. In such cases IntelliJ IDEA will try to shorten the classpath.

There are several approaches to shorten the classpath. Initially, IntelliJ IDEA tried to write the long classpath into the text file (which means an intermediate classloader to the application). But unfortunately, this didn’t work for some frameworks, e.g. JMock. Then, IntelliJ IDEA tried to use a more or less standard way, which was to pack the long classpath into the classpath.jar. Unfortunately, that didn’t work either, for some other frameworks.

And, sadly, there is no way to predict which kind of shortening would work for the user application. So the user is left having to make this decision. For Application, JUnit and TestNG configurations, v2017.3 provides a way to configure the shortener.

Starting with v2017.3, there is no more need to edit the settings of your IDE through the XML files.

IntelliJ IDEA 2017.3 provides a convenient way to specify the method to shorten command line, for each configuration.

Screen Shot 2017-10-09 at 08.58.33

In the Run/Debug Configuration dialog, a new field appeared: Shorten command line. The new field allows you to choose the way the IDE will shorten the command line from a drop-down list:

None: This is the default option. The IDE doesn’t shorten the long classpath. If the command line exceeds the OS limitation, the IDEA will not be able to run your application, but the tooltip will suggest configuring the shortener.

JAR Manifest: The IDE passes the long classpath via a temporary classpath.jar. The Original classpath is defined inside MANIFEST.MF as a Class-Path attribute in classpath.jar.

classpath file: The IDE will write a long classpath into a text file.

User-local default: Legacy property. This option is set automatically for projects created before this EAP. The IDE will configure this setting, depending on the value of the properties set in: idea/workspace.xml file, property: “dynamic.classpath” and idea.config.path/options/options.xml file, property: “idea.dynamic.classpath.jar”.
So you will have User-local default: none – if nothing was specified for the classpath shortener before, User-local default: JAR Manifest – if your settings specified the shortener via classpath, and User-local default: classpath file: – if your settings specified the shortener through the text file.

You can set up a default way to shorten the command line and use it as a template for further configurations. IntelliJ IDEA 2017.3 enables you to share your configuration with your colleagues, so all team members will have the same behavior for the application/tests, even on different operating systems. The only exception is for the parameter User-local default: this parameter won’t be shared if the configuration itself is shared. If you want the team to have the same experience, it’s advised to explicitly set this option.

Up until now, when the IDE shortened the classpath via classpath.jar, you would see only the classpath of the temporary jar: -classpath C:\Users\jetbrains\AppData\Local\Temp\classpath.jar.

Starting with IntelliJ IDEA 2017.3 you can preview the full command line if a long classpath was shortened via classpath.jar (JAR Manifest option in Run/Debug Configuration dialog box).

Screen Shot 2017-10-10 at 13.26.14

We love to hear from our users. Don’t forget to submit your feedback regarding this feature in IntelliJ IDEA.

Happy developing!

Comments below can no longer be edited.

10 Responses to IntelliJ IDEA: Configurable command line shortener

  1. Avatar

    Dmitry says:

    October 12, 2017

    Some more ideas for ways to shorten a command line:

    1) If a folder is present multiple times in the classpath and the classpath has all the jars from that folder – replace them all with “/*”

    2) Symlink (hard-link?) classpath jars into a temporary folder and use “-classpath /*”

    These should be fairly compatible. And do not require any special tricks like intermediate classloaders.

    There is one drawback though. The order of the jars enumeration is not specified.
    If it’s critical the user should use another shortening option.

    • Avatar

      Dmitry says:

      October 12, 2017

      Comment sanitizer swallowed ” both times before ‘/*’

      • Avatar

        Anna Kozlova says:

        October 12, 2017

        Hi Dmitry,
        thanks for the suggestions!

        1) What comes to my mind is that most people nowday use maven or gradle, and jars there are located per artifact id, per version. So, unfortunately, it won’t help much in those cases.


  2. Avatar

    Dmitry says:

    October 12, 2017

    .. [ folder ]

  3. Avatar

    Mike says:

    October 13, 2017

    How do you configure intellij to not delegate compilation to gradle?

    “Please take into the consideration, that in order to use the Smart Completion feature, the project needs to be compiled by IntelliJ IDEA, don’t delegate the compilation to Gradle.”

  4. Avatar

    Roman Koreshkov says:

    November 3, 2017

    “Configurable command line shortener” – it is long awaited feature. Now we can use IDEA for running a selected test from the test’s code. Awesome!

  5. Avatar

    ARIF SAIFEE says:

    March 1, 2018

    I have 2017.3 Ultimate. I am trying to run Cucumber tests in IntelliJ which fails as the command line is too long. However, there is NO COMMAND LINE SHORTENER OPTION.

    IntelliJ IDEA 2017.3.3 (Ultimate Edition)
    Build #IU-173.4301.25, built on January 15, 2018
    Licensed to Amazon Corporate, LLC / Arif Saifee
    Subscription is active until May 25, 2018
    JRE: 1.8.0_152-release-1024-b11 amd64
    JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
    Windows 10 10.0

  6. Avatar

    Tim Adams says:

    March 16, 2018

    I recommend LongPath Tool. Please try it.

  7. Avatar

    Dor says:

    July 9, 2018

    Why did you remove it from 2018 builds?
    Anyway this post solved it for me:

    • Avatar

      Kebron says:

      July 12, 2018

      Intellij 18.1.5 Ultimate.
      And the post from stackoverflow works for me!

Discover more