将带有java文件的目录转换为intellij中的java模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33531334/
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-08-11 14:45:19  来源:igfitidea点击:

Convert directories with java files to java modules in intellij

javaintellij-idea

提问by Michael Queue

I recently switched to using IntelliJ. I manually imported some projects and I guess I didn't do it correctly. They are all supposed to be java modules but they are just regular directory folders. Is there a way to convert them to java modules so I can run the programs or will I have to manually recreate new modules?

我最近改用 IntelliJ。我手动导入了一些项目,我想我没有正确执行。它们都应该是 java 模块,但它们只是普通的目录文件夹。有没有办法将它们转换为 java 模块,以便我可以运行程序,还是必须手动重新创建新模块?

enter image description here

在此处输入图片说明

采纳答案by kuporific

There are a few ways to handle this. If your project has an existing build framework such as gradle, maven, etc, generally you can navigate to

有几种方法可以处理这个问题。如果您的项目已有构建框架,例如 gradle、maven 等,通常您可以导航到

File > New > Project From Existing Sources...

File > New > Project From Existing Sources...

And then navigate to the gradle.build, pom.xml, or other framework specific build. When this project is created, all of the necessary source files should be properly identified.

然后导航到 gradle.build、pom.xml 或其他特定于框架的构建。创建此项目时,应正确标识所有必需的源文件。

Alternatively, you can also manually set the source directories by selecting the directory in the Project window, right clicking and selecting Mark Directory As > Sources Root.

或者,您也可以通过在“项目”窗口中选择目录,右键单击并选择 来手动设置源目录Mark Directory As > Sources Root

See also:

也可以看看:

回答by vvg

You should mark this folder as sourcedirectory in project settings or with right-click on folder.

您应该source在项目设置中或右键单击文件夹将此文件夹标记为目录。

回答by u3044595

If you get the directory from some version system and it has a maven pom.xmlconfiguration file, here's a solution:

如果你从某个版本系统获取目录并且它有一个 mavenpom.xml配置文件,这里有一个解决方案:

  • Find the pom.xmlin the directory.

  • Right click the pom.xml.

  • Then you can see the popup windows. Select the last item "add as maven project file".

  • Then, the maven build tool can automatically discern the directory as an module and import the specified jar dependencies.

  • pom.xml在目录中找到。

  • 右键单击pom.xml

  • 然后你可以看到弹出窗口。选择最后一项"add as maven project file"

  • 然后,maven 构建工具可以自动将目录识别为模块并导入指定的 jar 依赖项。