java IntelliJ IDEA 中的“模块依赖”和“库”有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12269733/
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
What is the difference between "Module Dependencies" and "Libraries" in IntelliJ IDEA?
提问by moorara
What is the difference between "Module Dependencies" and "Libraries" in IntelliJ IDEA when you want to add a .jar
library to your project? Also, What is the "Export" check box when you are adding your .jar
library to the "Module Dependencies" in IntelliJ IDEA?
当您想向.jar
项目添加库时,IntelliJ IDEA 中的“模块依赖项”和“库”之间有什么区别?另外,当您将.jar
库添加到 IntelliJ IDEA 中的“模块依赖项”时,“导出”复选框是什么?
In each of these ways, how are the classes and code inside the included .jar
library integrated into your final project (code) when creating the newly generated .jar
file?
在每种方式中,.jar
在创建新生成的.jar
文件时,包含库中的类和代码如何集成到您的最终项目(代码)中?
采纳答案by Roman C
Module dependencies are classes, archives, libraries and resources that your module files references. While a library is a set of class files stored in an archive or directory.
模块依赖项是您的模块文件引用的类、档案、库和资源。库是存储在存档或目录中的一组类文件。
Export check means if checked then this library will be implicitly added to the other module that references this one.
导出检查意味着如果选中,则该库将被隐式添加到引用此库的另一个模块中。
To create a .jarfile you need create an artifact. Artifact is a placeholder of the building output. There's predefined templates for creating .jar, .war, .eararchives. You can choose jar to build a jar artifact. By default it's defined empty and you need to define content of the artifact. You can drag-n-drop compiled output to it but don't do it with library archives. Because libraries in this case will be packaged inside the .jarfile and you will be required to create a separate classloader to load them before your application start. Instead you change the artifact type to Otherand drag .jarand dependent libraries into output root. This way library archives will be copied along with created .jar. You also need to create a MANIFEST.MF and specify Class-Paththere for dependent libraries. All files will be stored in the directory you specify for building the artifact. You can build it using Build Artifactmenu.
要创建.jar文件,您需要创建一个工件。Artifact 是建筑输出的占位符。有用于创建.jar、.war、.ear档案的预定义模板。您可以选择 jar 来构建 jar 工件。默认情况下,它被定义为空,您需要定义工件的内容。您可以将编译后的输出拖放到它,但不要使用库档案。因为在这种情况下,库将被打包在.jar文件中,您将需要创建一个单独的类加载器来在应用程序启动之前加载它们。相反,您将工件类型更改为Other并将.jar和相关库拖到输出根目录中. 这样库档案将与创建的.jar一起复制。您还需要创建一个 MANIFEST.MF 并在那里为依赖库指定类路径。所有文件都将存储在您为构建工件指定的目录中。您可以使用Build Artifact菜单构建它。
回答by Amir Pashazadeh
If your project contains multiple modules, "module dependency" defines dependencies between these modules, but libraries are compiled classes (usually jar files, optionaly containing theirs sources and javadocs) that are used by your module.
如果你的项目包含多个模块,“模块依赖”定义了这些模块之间的依赖关系,但库是你的模块使用的编译类(通常是 jar 文件,可选地包含它们的源和 javadoc)。
Each module can have its own libraries and artifacts (for example a result jar file), and can depend on other modules without circular dependency.
每个模块都可以有自己的库和工件(例如结果 jar 文件),并且可以依赖其他模块而没有循环依赖。
回答by CrazyCoder
Module Dependenciestab can contain Libraries, Exportmeans that a library from the module will be also available to another module that depends on this module.
Module Dependencies选项卡可以包含Libraries,Export意味着来自模块的库也可用于依赖于该模块的另一个模块。
Final jar with all the dependencies can be created using Artifacts.
可以使用Artifacts创建包含所有依赖项的最终 jar 。
回答by OSGI Java
“在 IntelliJ IDEA 中,可以在三个级别定义库:全局(可用于许多项目)、项目(可用于项目中的所有模块)和模块(可用于一个模块)。”
- Global library is set via Project Structure\Platform Settings\Global Libraries
- Project library is set via Project Structure\Project Settings\Libraries
- Module library is set via Project Structure\Project Settings\Modules\Dependencies
- 全局库通过 Project Structure\Platform Settings\Global Libraries 设置
- 项目库通过 Project Structure\Project Settings\Libraries 设置
- 模块库通过 Project Structure\Project Settings\Modules\Dependencies 设置