Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using IntelliJ Path Variables, how to set system properties in Tomcat server Run Configuration?

In Eclipse you could set the -D options to include {} variables that were defined elsewhere within your IDE settings. IntelliJ would seem to provide this feature with Path Variables. However, if you follow their Help documents, you're supposed to be able to reference these variables between $dollar_characters$. Further research would seem to indicate that that only applies to the interior of your project files and the replacement is done during build time.

I'm trying to create a shared server configuration where a couple of the system properties can be swapped out by the other developers, but this one has me stumped.

like image 886
Joel Wilson Avatar asked Mar 06 '13 18:03

Joel Wilson


3 Answers

You can directly set your VM options on the Tomcat Server Run/Debug configuration window by adding it to the VM Options input field. You can directly put in your -Dcustom_property=value into that field and then access it through System.getProperty("customer_property").

like image 181
RuntimeBlairror Avatar answered Jun 04 '23 19:06

RuntimeBlairror


After much digging and research into seemingly unrelated issues, I began to get a larger picture of how to accomplish this:

  1. Set your Path Variables as needed.
  2. Create your Run Configuration that you intend to share and check the Share checkbox.
  3. Put in the stubs (i.e. -Dsystem.property="variable here") in the VM options field of your configuration.
  4. Find your configuration in .idea/runConfigurations and replaces the stubs with $PATH_VARIABLE$, placing them inside of quotes if the value will include spaces.
  5. Re-open the Edit Configuration screen for your Run Configuration and note that the variable expansion has succeeded. Even better, check it in and have a colleague check it out (after setting their own Path Variables) and note that the variable expansion works with their custom values.

Note: It may seem like you ought to be able to put those $PATH_VARIABLES$ directly into those config screens, but it only seems to work if you've edited the XML files directly.

like image 26
Joel Wilson Avatar answered Jun 04 '23 18:06

Joel Wilson


Joel Wilson, thanks for your exploration on using $PATH_VARIABLES$ in IntelliJ Configurations.

To embellish your finding a bit; I found out that if a config file changes at the file system it gets reloaded by IJ right then ($PATH_VARIABLES$ get expanded). However if you make the change in IJ Preferences it doesn't.

But if you: touch ~/IntelliJ/yourProject/.idea/runConfigurations *.xml

That is enough to have your configurations reloaded.
I also found out that if you close and reopen IJ, that these will be autoexpanded at that time too.

And if you look at those .xml files, the expanded values don't ever get stored. The expansion happens any time you load IJ, or change the files.

Bottom line if you want to share common configurations in a repo - and then setup the user variable stuff in IJ PATH variables - you can and they will be automatically expanded.

If you happen to change the PATH variables, the new values will contain the modified PATH_VARIABLE content.

If you were to look at the files at OS level, you'll see the variables preserved. But if you look in the Configuration editor, the substituted values will always show there (so you can't directly see that they used a variable). Best to look at the OS file for that. jim

like image 36
Jim Kohl Avatar answered Jun 04 '23 18:06

Jim Kohl