What does the dynamic.classpath flag do? (IntelliJ project settings)
Asked Answered
P

2

42

Within the file .idea/workspace.xml the following can be found:

<component name="PropertiesComponent">
  ...
  <property name="dynamic.classpath" value="false" />
</component>

What is the purpose of the dynamic.classpath flag?

Setting it to true happens to be a workaround for an IntelliJ bug. But I'm also curious if it has any side effects.

Pave answered 31/1, 2011 at 16:46 Comment(0)
S
44

This option controls how classpath is passed to the JVM: via the command line, or via a file. Most operating systems have maximum command line limit, when it's exceeded, IDEA will not be able to run your application.

When command line is longer than 32768 chars, IDEA suggests you switching to the dynamic classpath. Long classpath is written to a file, then read by the application launcher and loaded via system classloader.

If you are interested in the implementation details, you can check IDEA Community edition source code, JdkUtil.java file, setupJVMCommandLine method.

Sundried answered 31/1, 2011 at 17:9 Comment(1)
Consequently, if your application or a unit test is messing with classloaders (e. g. invoking URLClassLoader.getURLs() and processing its result) -- then the application (or the test) may fail miserably for no obvious reason if dynamic.classpath is true.Grangerize
D
23

A side effect with IntelliJ 9.0.4 is that after turning the option on, the class path is no longer complete.

In my case the option was turnend on after i choose "yes" in an error dialog when running all unit tests in a specific package. The error message reads "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?"

After this some tests failed because the needed classes from other modules, which were than missing in the classpath.

I found no dialog where i could switch it back. I had to edit the .iws file manually and switched the dynamic.classpath option back to "false".

Darkness answered 8/4, 2011 at 6:46 Comment(1)
I still experience the same problem with IntelliJ 13.1. I've raised a bug: youtrack.jetbrains.com/issue/IDEA-130440Berley

© 2022 - 2024 — McMap. All rights reserved.