Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ Problem with+get current working directory

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.

like image 266
Aniruddha Avatar asked Sep 18 '11 14:09

Aniruddha


People also ask

How do I change the current directory in IntelliJ?

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.

How do I navigate a path in IntelliJ?

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.

Can start process working directory does not exist?

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.

What is meant by working directory?

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.


2 Answers

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.

like image 73
CrazyCoder Avatar answered Oct 07 '22 06:10

CrazyCoder


You can edit the working directory from within the run configurations dialog.

like image 32
Dave Newton Avatar answered Oct 07 '22 06:10

Dave Newton