How to use Relative Paths in Run/Debug Configurations?

Is it possible to use Relative Paths in Run/Debug configurations? For example, Mocha test configurations seem to require Absolute paths which means if you move or copy the project all the test configurations break. I'd like to:

1) Define the location of the Mocha tool relative to the working directory. This is important when using different mocha versions and --compilers on the project level. Otherwise, for ES2015 you have to create long options paths to Babel, etc.

2) Define the location of the test file itself relative to the working directory

I've tried various formats:


What is the proper way to specify tool location and test file location relative to the current project's working directory?

Thanks for any help with this.

Comment actions Permalink

No, you can't enter relative paths there.

In .xml file that stores Mocha run configuration, path to tests dir, etc. is stored relative to project root, using $PROJECT_DIR$ macro:



so the tests path doesn't change when you move/copy your project to different location

Path to mocha  package is unfortunately saved as an absolute path, but WebStorm detects Mocha package in project dir, if any, and offers it in paths dropdown in 'Mocha package' field

Comment actions Permalink

Now (2019.1) it is possible to use relative path for working directory in run/debug configurations in Linux. It looks like "foo/bar_test". Will it also possible in Windows?

Also, it is possible to use relative path there for VM options in Linux. It looks like "./foo/bar_test". Will it possible in Windows?

Comment actions Permalink

This is a big limitation when you want to share a project. The path in my machine is not the same as other developers.
For instance, to the mvnw wrapper, I create a shell script run configuration, but I'm forced to provide the absolute path to the script, despite there is a working directory field.  Using the $PROJECT_DIR$ doesn't work.

Any recommendations for this use case?

Comment actions Permalink

>Using the $PROJECT_DIR$ doesn't work.


what do you mean saying this doesn't work? as it's written above, absolute paths specified in UI are stored using $PROJECT_DIR$  in .xml files so the configuration is actually shareable

Comment actions Permalink

I got it now. My confusion was because I can't use the $PROJECT_DIR$ macro on the UI. But when I select a script file form the project dir, the absolute path is replaced by that macro on workspace.xml. Thanks.

<option name="SCRIPT_PATH" value="$PROJECT_DIR$/mvnw" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
Comment actions Permalink

how can i save absolute path?

I set <option name="EXE_PATH" value="C:/Program Files (x86)/IIS Express/iisexpress.exe" />

but it always change to <option name="EXE_PATH" value="$PROJECT_DIR$/../../../../Program Files (x86)/IIS Express/iisexpress.exe" />



Comment actions Permalink

is EXE_PATH a new path variable (Settings | Appearance & Behavior | Path Variables)? they are always saved with absolute paths for me...

Comment actions Permalink

As a customer I could confirmed the same behavior with intelliJ ultimate version 2018.2.4 (we are stuck with it because of some compatibility issues with our old JBoss version on some of our projects) and version 2021.2

Paths appear are Absolute in the "edit configurations" pannel, but are stored as relative to $PROJECT_DIR$ in the [configuration_name].xml file located under the .idea/runConfigurations folder. 

If you manually modified the xml file to have absolute path with a text editor, then go to "edit configuration" to read the parameter, touch one then click OK, they are changed back to relative paths in the xml. They are still displayed as absolute when you open them again in IntelliJ Idea, but persisted as relative in the .xml.

I'm looking for an existing option, linked to the runConfiguration (because some of them must use relative paths, some of them must use absolute ones) to NOT replace them when saving the xml, but I can't find any.

A proposed solution which doesn't need an additional button: store what we write in the field in the xml literally, and when resolving the path, do so as if current working directory is project directory (absolute path resolved as absolute, relative paths resolved as relative to project directory).

Comment actions Permalink

As I understand, (latest PyCharm Community version), if we choose the project root path through the icon that selects it, in the file browsing dialog of the working directory field in a run configuration, then it shows in the UI as absolute but is not stored as an absolute path in the exported .run file.

It adds a line like follows to the .run file which obviously takes care of that:

<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />

So essentially this is already a feature. Thanks for this.


Please sign in to leave a comment.