changing the execution path of a maven module

I have a maven project with several modules in nested directories.
I need to be able to run a main method or a test case in a maven module such as its execution path is the root where the module is located, not the one of the root maven project, as it seems to be by default.

For example, if I implement the class below, belonging to one of the modules, and execute its main method I currently see in the console the absolute path of the parent project, not the one of the module, as I expected:

 
public class X {

    public static void main(String[] args) {
        System.out.println(new File(".").getAbsolutePath()
        );
    }

}




What is the easiest way to change this in IntelliJ? I already took a look to the module properties but I cannot see something related to what I need.
Ideally, I am looking for a single place setting, instead of going module by module changing each execution settings.

Thanks in advance!

4 comments
Comment actions Permalink

Specify $MODULE_DIR$ as the working directory of the run/debug configuration. You can set it for the default configuration so that all the new run/debug configurations (even temporary) will use this default.

0
Comment actions Permalink

Thanks. That answered my question. It would be cool if next to the "Working directory" field there was a button allowing me to choose from the possible relevant variables similar to the $MODULE_DIR$ you mentioned.
If there is a way to see such a list from the Run/Debug configuration window, please let me know!

0
Comment actions Permalink

Update:

I see that in the Run/Debug Configurations window, there is a button for selecting proper variables for the JUnit category, although it is not present when selecting the Maven category. Any idea why is that?

0
Comment actions Permalink

It's commonly used for JUnit tests and was added to meet the popular request: https://youtrack.jetbrains.com/issue/IDEA-60965 .

0

Please sign in to leave a comment.