Here is my maven project structure
ProjectParent -Class1 -Class2 -Module1 (another sub directory) --Module1Class1 --Module1Class2
Now when I run Module1Class1 from IntelliJ my current working directory is where ProjectParent directory, but when I run Module1Class1 from eclipse, my current working directoru is ProjectParent/Module1 directory.
Why this is different in intellij & how can I change this, so my current directory is always from where my class started execution like in this example 'Module1Class1' directory.
If you go to File > project Structure, click on "modules" on the left, and then select the module, and then select the "sources" tab it will show the root directory of the module. It's the top most path in the tree of directories.
Open the Project Structure dialog (File | Project Structure Ctrl+Alt+Shift+S ). In Project Settings, select Project and in the Project compiler output field, specify the corresponding path. For modules, select Modules, the module you need and the Paths tab.
It happens because when you create a file it automatically assigns the working directory to it's configuration, which of course is the one where you created it. You can change that by going into Run -> Edit Configurations . Click on the folder icon in Script path: and correct the path to the file.
In computing, the working directory of a process is a directory of a hierarchical file system, if any, dynamically associated with each process. It is sometimes called the current working directory (CWD), e.g. the BSD getcwd function, or just current directory.
You should edit the template Run/Debug configuration and specify $MODULE_DIR$
variable in the Working directory field.
All the new configurations will inherit this default setting and the variable will be substituted with the directory of the module that you want to run.
There is a feature request to make it the default setting, please vote.
You can edit the working directory from within the run configurations dialog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With