java IntelliJ 问题 + 获取当前工作目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7461987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 20:04:28  来源:igfitidea点击:

IntelliJ Problem with+get current working directory

javaintellij-idea

提问by Aniruddha

Here is my maven project structure

这是我的 Maven 项目结构

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.

现在,当我从 IntelliJ 运行 Module1Class1 时,我当前的工作目录是 ProjectParent 目录,但是当我从 Eclipse 运行 Module1Class1 时,我当前的工作目录是 ProjectParent/Module1 目录。

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.

为什么这在 intellij 中有所不同以及我如何更改它,所以我的当前目录总是从我的类开始执行的位置开始,就像这个例子中的“Module1Class1”目录一样。

回答by CrazyCoder

You should edit the template Run/Debug configuration and specify $MODULE_DIR$variable in the Working directoryfield.

您应该编辑模板运行/调试配置并$MODULE_DIR$工作目录字段中指定变量。

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.

有一个功能要求使其成为默认设置,请投票

回答by Dave Newton

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

您可以从运行配置对话框中编辑工作目录。