java maven - 两种不同的根 pom
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16766692/
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
maven - two different root poms
提问by Kevin Rave
I am new to Maven. I am given a new project and that has the following structure.
我是 Maven 的新手。我得到了一个新项目,它具有以下结构。
Data_Res
|
---res-search
| |
| -----res-hast
| | |
| | ------src/main....
| | |
| | ------pom.xml
| -----res-haster
| | |
| | ------src/main....
| | |
| | ------pom.xml
| |
| ----pom.xml
|
|
---pom.xml
---sonar_pom.xml
I don't see modules section in root pom.xml. But I do see modules section in sonar_pom.xml. It does not include all child nodes. Can a folder/project have two poms? Or can we execute them separately?
我在根 pom.xml 中没有看到模块部分。但我确实在 sonar_pom.xml 中看到了模块部分。它不包括所有子节点。一个文件夹/项目可以有两个 poms 吗?或者我们可以分别执行它们吗?
- How do I interpret this one? Sub-modules or individual projects? Are there any metrics to find out?
- I was told to run
mvn clean install
on root pom. I did that. I was asked to verify if all dependencies for one of the sub-folders are provided. How to check these? I can see some files under .m2 folder in my home directory. - How do I build/package this? I am going to be working on one of the sub-folders. Not sur e if its a separate project or sub-module. In that case, can I directly go to that folder and run
mvn package / build
from that folder (pom.xml exists)?
- 我如何解释这一点?子模块还是单个项目?是否有任何指标可以找出?
- 我被告知要
mvn clean install
在 root pom上运行。我就是这么做的。我被要求验证是否提供了子文件夹之一的所有依赖项。如何检查这些?我可以在我的主目录中的 .m2 文件夹下看到一些文件。 - 我如何构建/打包它?我将处理其中一个子文件夹。不确定它是一个单独的项目还是子模块。在这种情况下,我可以直接转到该文件夹并
mvn package / build
从该文件夹运行(pom.xml 存在)吗?
回答by Karthikeyan Vaithilingam
When you execute a goal (e.g mvn install)
maven will check for pom.xml on the folder of the execution if pom.xml present it will perform the goal for that folder (i.e project) if there are any modules mentioned the same goal will be executed on the modules, this operation is recursive.
当您执行目标时,(e.g mvn install)
maven 将检查执行文件夹上的 pom.xml,如果 pom.xml 存在,它将执行该文件夹(即项目)的目标,如果提到任何模块,将在模块上执行相同的目标,这个操作是递归的。
Can a folder/project have two poms?
一个文件夹/项目可以有两个 poms 吗?
Yes you can have multiple poms for a project, but the default is pom.xml if you want to use alternate pom file you can use -f
to mention the alternate pom file in your case mvn -f sonar_pom.xml clean install
, probaly that pom file is used for sonar.
是的,您可以为一个项目使用多个 pom,但默认值是 pom.xml,如果您想使用备用 pom 文件,您可以-f
在您的案例中使用备用 pom 文件mvn -f sonar_pom.xml clean install
,可能该 pom 文件用于声纳。
How do I interpret this one? Sub-modules or individual projects? Are there any metrics to find out?
我如何解释这一点?子模块还是单个项目?是否有任何指标可以找出?
Every project has a pom.xml can be build independently if the parent and all dependecies are present in your local maven repo.
如果本地 maven 存储库中存在父项和所有依赖项,则每个项目都有一个 pom.xml 可以独立构建。
I was told to run mvn clean install on root pom. I did that. I was asked to verify if all dependencies for one of the sub-folders are provided. How to check these? I can see some files under .m2 folder in my home directory.
我被告知要在 root pom 上运行 mvn clean install。我就是这么做的。我被要求验证是否提供了子文件夹之一的所有依赖项。如何检查这些?我可以在我的主目录中的 .m2 文件夹下看到一些文件。
To verify the dependency check your local maven repo the default is ~/.m2/repository
, but the settings can be changed in settings.xml. Check ~/.m2/settings.xml
if the file doesn't exists you can find the global settings in <maven_home>/conf/settings.xml
copy it to ~/.m2/
then it can be overridden check the following tag <localRepository>/path/to/local/repo</localRepository>
要验证依赖项,请检查您的本地 Maven 存储库,默认为~/.m2/repository
,但可以在 settings.xml 中更改设置。检查~/.m2/settings.xml
文件是否不存在,您可以在<maven_home>/conf/settings.xml
将其复制到全局设置中找到它,~/.m2/
然后它可以被覆盖检查以下标签<localRepository>/path/to/local/repo</localRepository>
How do I build/package this? I am going to be working on one of the sub-folders. Not sur e if its a separate project or sub-module. In that case, can I directly go to that folder and run mvn package / build from that folder (pom.xml exists)?
我如何构建/打包它?我将处理其中一个子文件夹。不确定它是一个单独的项目还是子模块。在这种情况下,我可以直接转到该文件夹并从该文件夹运行 mvn package / build (pom.xml 存在)?
As I mentioned earlier you can do mvn package
on your module if you have the parent and all dependencies. You can get these in combination of two ways
正如我之前提到的,mvn package
如果您拥有父模块和所有依赖项,则可以在模块上执行操作。您可以通过两种方式获得这些
- Install those in your system using
mvn install
or - using remote repositories
- 使用
mvn install
或在您的系统中安装它们 - 使用远程仓库
回答by Kurt
Just to add to the already correct answer: in eclipse I had to create a new "run configuration" under the "Maven Build" run configs. I set the base directory to the standard
只是为了添加到已经正确的答案:在 Eclipse 中,我必须在“Maven Build”运行配置下创建一个新的“运行配置”。我将基本目录设置为标准
${project_loc:connect}
${project_loc:connect}
and the "Goals" field to
和“目标”字段
-f pom_deploy.xml install -T 1C
-f pom_deploy.xml 安装 -T 1C
Then I could right-click on the custom pom_deploy.xml --> run as... --> run configurations --> Custom Maven Deploy
然后我可以右键单击自定义 pom_deploy.xml --> 运行方式... --> 运行配置 --> 自定义 Maven 部署
The '-T 1C' is optional and tells Maven to use multiple processors simultaneously for the build/compile process.
'-T 1C' 是可选的,它告诉 Maven 在构建/编译过程中同时使用多个处理器。