简体   繁体   English

在Maven项目中管理库依赖

[英]Managing libraries dependencies in Maven project

As a beginner with Maven I have a little problem to fully understand and find the best way how to manage all dependencies in my Java Application. 作为Maven的初学者,我有一个小问题,可以全面了解并找到如何在Java应用程序中管理所有依赖项的最佳方法。 In my app there is about 20-30 external libraries. 在我的应用程序中,大约有20-30个外部库。 These libraries have own dependency libraries, some of these libraries requires different version of one particular library. 这些库具有自己的依赖库,其中一些库需要一个特定库的不同版本。 How can be this situation solved? 这种情况如何解决?

My primary problem is how to find out all dependencies of my librabries and don't forget any of them. 我的主要问题是如何找出我所有liblibries的依赖项,并且不要忘记其中的任何一个。 When I was searching for a solution I found that http://search.maven.org/ website offers for all libraries own pom.xml file with all dependency libraries that this particular library requires. 当我寻找解决方案时,我发现http://search.maven.org/网站为所有库提供了自己的pom.xml文件,以及该特定库所需的所有依赖库。 Eg this is a pom.xml for Spring-core 3.2.5 . 例如,这是Spring-core 3.2.5的pom.xml。

What are these files intended for? 这些文件的用途是什么? Can be these files be used in Maven project to specify dependencies? 可以在Maven项目中使用这些文件来指定依赖项吗? I hope so, because it consists valuable information about one particular library and the structure of this pom.xml file is the same as in the standard Maven pom.xml file. 我希望如此,因为它包含有关一个特定库的有价值的信息,并且此pom.xml文件的结构与标准Maven pom.xml文件中的结构相同。

If can be used directly in Maven, where to place these files? 如果可以直接在Maven中使用,这些文件放在哪里? I have studied standard Maven project directory structure but I have no idea where to place them. 我研究了标准的Maven项目目录结构,但不知道将它们放置在何处。

If can't be used, what are these pom.xml files intended for? 如果无法使用,这些pom.xml文件的用途是什么? Is it safe to copy out dependencies and use in my Maven project pom.xml file? 复制依赖项并在我的Maven项目pom.xml文件中使用是否安全? This could be a solution how to find out all needed dependencies. 这可能是解决方案,以找出所有需要的依赖项。

Just make sure you have your app's dependencies in the pom.xml file. 只需确保在pom.xml文件中具有应用程序的依赖项即可。

The files in repositories carry the information about that particular library dependencies. 存储库中的文件包含有关该特定库依赖项的信息。 You don't have to place any additional files besides your application's pom.xml file. 除了应用程序的pom.xml文件之外,您不必放置任何其他文件。 Maven will take care of including dependencies of dependencies while packaging your application. Maven将在打包应用程序时照顾包括依赖项的依赖项。

Put all your dependencies in pom.xml file(s), yes. 将所有依赖项放入pom.xml文件,是的。 That way all required dependencies will automatically be downloaded from Maven repository and packaged into your build artifact. 这样,所有必需的依赖项都将从Maven存储库中自动下载并打包到您的构建工件中。 You mostly don't have to worry about anything else than whether you set up the scopes correct. 除了是否正确设置范围外,您几乎不必担心其他任何事情。 Use dependencyManagement on root project, if you have a multimodule Maven project. 如果您有多模块Maven项目,请在根项目上使用dependencyManagement。

pom.xml goes to the root of your project, BTW. pom.xml转到项目的根目录BTW。

Read more here . 在这里阅读更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM