简体   繁体   English

单个或多个Maven pom.xml配置文件?

[英]Single or Multiple Maven pom.xml configuration files?

I would like to ask these questions related to pom.xml files in Maven projects. 我想问一下与Maven项目中的pom.xml文件有关的这些问题。

  • What is a reason to have multiple pom.xml for all dependency libraries instead of having all dependencies in one single pom.xml ? 什么是原因有多个pom.xml所有依赖库,而不必在一个单一的所有依赖pom.xml
  • Where should be these pom.xml files in Maven project placed? Maven项目中的这些pom.xml文件应该放在哪里?

This is an example of pom.xml for Spring framework - http://search.maven.org/remotecontent?filepath=org/springframework/spring-core/3.2.5.RELEASE/spring-core-3.2.5.RELEASE.pom 这是Spring框架的pom.xml示例 - http://search.maven.org/remotecontent?filepath=org/springframework/spring-core/3.2.5.RELEASE/spring-core-3.2.5.RELEASE。 POM

  • What is a reason to have multiple pom.xml for all dependency libraries instead of having all dependencies in one single pom.xml? 为所有依赖库创建多个pom.xml而不是在一个pom.xml中包含所有依赖项的原因是什么?

A maven project can be made of many artifacts. maven项目可以由许多工件组成。 One artifact may be a String manipulation library. 一个工件可能是String操作库。 Another may be a webapp that uses that String manipulation library. 另一个可能是使用该String操作库的webapp。

Here's why you shouldn't put all your dependencies in one pom: Your String manipulation library should not have a reference to the servlets.jar just because an unrelated pom is a webapp. 这就是为什么你不应该将所有依赖项放在一个pom中:你的String操作库不应该只是因为一个不相关的pom是一个webapp而引用了servlets.jar。 Each artifact should have only what it needs in its classpath. 每个工件应该只有它在它的类路径需要

(You may be interested to learn about the dependencyManagement tag, but it does not directly relate to your question.) (您可能有兴趣了解dependencyManagement标记,但它与您的问题没有直接关系。)

  • Where should be these pom.xml files in Maven project placed? Maven项目中的这些pom.xml文件应该放在哪里?

As @MariuszS linked to, here's the Standard Directory Layout . 正如@MariuszS链接到的,这是标准目录布局

At the top level files descriptive of the project: a pom.xml file (and any properties, maven.xml or build.xml if using Ant). 在描述项目的顶级文件中: pom.xml文件 (以及任何属性,如果使用Ant,则为maven.xml或build.xml)。 In addition, there are textual documents meant for the user to be able to read immediately on receiving the source: README.txt, LICENSE.txt, etc. 此外,还有一些文本文档供用户在接收源时立即读取:README.txt,LICENSE.txt等。

This depends on your project, if project is small and product of this project (artifact) is only one then one pom is enough. 这取决于你的项目,如果项目很小,这个项目(工件)的产品只有一个,那么一个pom就足够了。 But if your project have many artifacts (libraries, WARs, EARs etc) then for every artifact pom is required (generally). 但是,如果您的项目有许多工件(库,WAR,EAR等),则需要(通常)每个工件pom。

Maven concept is that one project definition (POM) generate only one artifact (there are exceptions). Maven概念是一个项目定义(POM)只生成一个工件(有例外)。 Every project should have separate directory with pom.xml inside and source directories if needed. 如果需要,每个项目都应该有pom.xml内部和源目录的单独目录。

One maven project can build two diffrent apps (for example desktop and webapp). 一个maven项目可以构建两个不同的应用程序(例如桌面和webapp)。 This diffrent applications has diffrents dependencies. 这种不同的应用程序具有差异依赖性。

Sample multimodule project structure: https://github.com/peter-lawrey/Java-Chronicle 示例多模块项目结构: https//github.com/peter-lawrey/Java-Chronicle

Read more 阅读更多

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

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