Intellij - 像在 Eclipse 中一样添加项目依赖项

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

Intellij - Add project dependency like in Eclipse

javaeclipseintellij-idea

提问by user2336315

I'm switching to Intellij and trying to do the same thing as in Eclipse. In Eclipse, you can add a project as a dependency in another project (project properties -> "Java Build Path" -> "Projects" -> Click on my library project).

我正在切换到 Intellij 并尝试做与 Eclipse 相同的事情。在 Eclipse 中,您可以将一个项目作为依赖项添加到另一个项目 ( project properties -> "Java Build Path" -> "Projects" -> Click on my library project) 中。

The current situation is that I'm developing a library and I can test the features in another project without building the jar file every time I add new stuff to the library.

目前的情况是我正在开发一个库,我可以在另一个项目中测试功能,而无需每次向库添加新内容时构建 jar 文件。

I'm trying to achieve this with Intellij but without success (the projects are both imported in Intellij).

我正在尝试使用 Intellij 来实现这一点,但没有成功(这些项目都是在 Intellij 中导入的)。

How can I do that?

我怎样才能做到这一点?

回答by acanby

File > Project Structure. Then choose your module, and add any dependency, either Jar, Library or Module:

文件 > 项目结构。然后选择您的模块,并添加任何依赖项,Jar、Library 或 Module:

IntelliJ Screenshot

IntelliJ 截图

Larger image here: http://i.imgur.com/rjdxJHx.png

更大的图片在这里:http: //i.imgur.com/rjdxJHx.png

回答by Thirumalai Chellam Balagopalan

From File -> project structure, select Modules. You will be presented with all the added projects. Click a project and from the right hand side select Dependencies tab. This will show you projects that are not imported in red coloured text. HTH

从文件 -> 项目结构,选择模块。您将看到所有添加的项目。单击一个项目,然后从右侧选择 Dependencies 选项卡。这将显示未以红色文本导入的项目。HTH

回答by Emerica

File > Project Structure > Project Settings > Modules

文件 > 项目结构 > 项目设置 > 模块

Project Structure

项目结构

  1. Add the module you want to add as dependency.
  2. Add your module dependency in your project.
  1. 添加要添加为依赖项的模块。
  2. 在您的项目中添加您的模块依赖项。

If you use Mavenyou'll see the following message:

如果您使用Maven,您将看到以下消息:

Module 'your-module' is imported from Maven. Any changes made in its configuration may be lost after reimporting.

模块“您的模块”是从 Maven 导入的。重新导入后,对其配置所做的任何更改都可能丢失。

→ Add your project to your pom.xml

→ 将您的项目添加到您的pom.xml

If you don't do that, your dependency will be removed each time you reimport/refresh maven projects.

如果不这样做,则每次重新导入/刷新 maven 项目时都会删除您的依赖项。