Classpath for Run/Debug Application requires platform-specific path separators and idea_rt.jar

Answered

In our project, we have created some Run/Debug Application configurations that are shared with out community.  This configuration is used to start Tomcat and the classpath required for this is CATALINA_HOME/bin/* when starting this application in Debug mode.  However, when starting the application in Run mode, we find that the idea_rt.jar file is required.  Without it, the following error is produced:

/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/java -Dcatalina.base=./ -Dcatalina.home=./ -Djava.io.tmpdir=./temp -Ddevmode=true -ea -Dsun.io.useCanonCaches=false -Xmx1G -XX:MaxPermSize=160M -classpath ./bin/* -Didea.launcher.port=7533 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 com.intellij.rt.execution.application.AppMain org.apache.catalina.startup.Bootstrap start
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=160M; support was removed in 8.0
Error: Could not find or load main class com.intellij.rt.execution.application.AppMain

To include the idea_rt.jar file in the classpath, we use the following in our shared runConfiguration:

-classpath "./bin/*:$APPLICATION_HOME_DIR$/lib/idea_rt.jar"

However, because we develop on both Windows and Macs, the checked in version of this file will have the incorrect path separator for one of the platforms (either : or ;). 

This leads to a few questions

  • Why is this jar file required at all and only for the Run mode? (And if it is required, could IntelliJ add it to the classpath by itself?)
  • Is there a way to parameterize the path separator in this classpath definition in our shared configurations so the proper separator is used for each platform?
  • If, instead, it is recommended to use a module classpath in the configuration, thus eliminating the need for the -classpath command line argument, is there a recommended way to create a module that includes just the jar files we need for running within IntelliJ when using a Gradle build?  My workaround thus far has been to create a dummy .iml file in the .idea/modules directory that contains just these jar files, but this seems rather hacky, and we have been trying to avoid putting .iml files into our version control since converting to Gradle because otherwise the Gradle sync will generate these files for you.  Is there a better way?
0
1 comment

1. This file is needed to provide graceful shutdown/exit/stacktrace features, workaround OS command line length limits and perform other communications between IDE and the running process. You can disable it by adding idea.no.launcher=true into .vmoptions: https://intellij-support.jetbrains.com/hc/articles/206544869,

2. No, run configurations are not designed to manually specify the classpath, all the classpath elements are generated automatically before launch. If the command line is too long and exceeds OS limitation, a temp .jar file is generated that links classpath via Manifest.MF file instead. There are open feature requests to allow classpath customization for run configurations, like https://youtrack.jetbrains.com/issue/IDEA-160167.

3. It's a valid workaround until IDEA-160167 is addressed.

0

Please sign in to leave a comment.