IntelliJ IDEA中“模块依赖关系”和“库”之间有什么区别?

时间:2021-05-13 13:33:35

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库中的类和代码如何集成到最终项目(代码)中?

3 个解决方案

#1


12  

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 .jar file you need create an artifact. Artifact is a placeholder of the building output. There's predefined templates for creating .jar, .war, .ear archives. 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 .jar file and you will be required to create a separate classloader to load them before your application start. Instead you change the artifact type to Other and drag .jar and 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-Path there for dependent libraries. All files will be stored in the directory you specify for building the artifact. You can build it using Build Artifact menu.

要创建.jar文件,您需要创建一个工件。工件是建筑物输出的占位符。有预定义的模板用于创建.jar,.war,.ear档案。您可以选择jar来构建jar工件。默认情况下,它定义为空,您需要定义工件的内容。您可以将已编译的输出拖放到它,但不要使用库存档。因为在这种情况下,库将打包在.jar文件中,并且您需要创建一个单独的类加载器以在应用程序启动之前加载它们。而是将工件类型更改为“其他”,并将.jar和依赖库拖动到输出根目录中。这样,库存档将与创建的.jar一起复制。您还需要创建一个MANIFEST.MF并在那里为依赖库指定Class-Path。所有文件都将存储在您为构建工件指定的目录中。您可以使用Build Artifact菜单构建它。

#2


8  

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文件),并且可以依赖于没有循环依赖的其他模块。

#3


4  

Module Dependencies tab can contain Libraries, Export means 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。

#1


12  

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 .jar file you need create an artifact. Artifact is a placeholder of the building output. There's predefined templates for creating .jar, .war, .ear archives. 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 .jar file and you will be required to create a separate classloader to load them before your application start. Instead you change the artifact type to Other and drag .jar and 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-Path there for dependent libraries. All files will be stored in the directory you specify for building the artifact. You can build it using Build Artifact menu.

要创建.jar文件,您需要创建一个工件。工件是建筑物输出的占位符。有预定义的模板用于创建.jar,.war,.ear档案。您可以选择jar来构建jar工件。默认情况下,它定义为空,您需要定义工件的内容。您可以将已编译的输出拖放到它,但不要使用库存档。因为在这种情况下,库将打包在.jar文件中,并且您需要创建一个单独的类加载器以在应用程序启动之前加载它们。而是将工件类型更改为“其他”,并将.jar和依赖库拖动到输出根目录中。这样,库存档将与创建的.jar一起复制。您还需要创建一个MANIFEST.MF并在那里为依赖库指定Class-Path。所有文件都将存储在您为构建工件指定的目录中。您可以使用Build Artifact菜单构建它。

#2


8  

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文件),并且可以依赖于没有循环依赖的其他模块。

#3


4  

Module Dependencies tab can contain Libraries, Export means 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。