eclipse “Mavenize”一个项目是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3372955/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:57:00  来源:igfitidea点击:

What does it mean to "Mavenize" a project?

eclipsemaven-2netbeans

提问by stinkycheeseman

I've recently been asked to mavenize an existing project, and I don't know exactly what that means. On the maven website it outlines how to create a maven project from scratch, but what if I've already got a substantial amount of code?

我最近被要求对现有项目进行 mavenize,但我不知道这究竟意味着什么。在 maven 网站上,它概述了如何从头开始创建 maven 项目,但如果我已经有了大量代码怎么办?

I'm comfortable working on the command line or in Eclipse/Netbeans. I know there are a lot of plugins for the 2 IDE's that make this kind of thing easierbut I don't know where to start.

我很习惯在命令行或 Eclipse/Netbeans 中工作。我知道 2 个 IDE 有很多插件可以让这种事情变得更容易,但我不知道从哪里开始。

Is there anything more to it than just writing a pom file that has all the dependencies in it?

除了编写一个包含所有依赖项的 pom 文件之外,还有什么其他的吗?

采纳答案by Andrzej Doyle

To "Mavenize" simply means to write a POM (and possibly move code around) so that it builds in Maven.

“Mavenize”只是意味着编写一个 POM(并可能移动代码)以便它在 Maven 中构建。

Often the easiest way to do this is to restructure your code slightly so it matches Maven conventions (e.g. move "sources" to "src/main/java", and explicitly split up separate modules). You canignore the conventions, and tell Maven how you're storing your classes etc., but in general a small bit of pain up front to make most of Maven then work "out of the box" is worth investing in.

通常,最简单的方法是稍微重构您的代码,使其符合 Maven 约定(例如,将“源”移动到“src/main/java”,并明确拆分单独的模块)。您可以忽略这些约定,并告诉 Maven 您如何存储您的类等,但一般来说,让 Maven 的大部分内容“开箱即用”的前期工作是值得投资的。

Chances are the vast majority of your Ant (or similar) file is boilerplate, which was the idea behind Maven in the first place. However, there may be some bespoke stuff in there (e.g. test classes that start with "TestIntegration" should only be run on nightly builds) which you'll need to reproduce in Maven.

很有可能您的 Ant(或类似)文件的绝大部分都是样板文件,这首先是 Maven 背后的想法。但是,那里可能有一些定制的东西(例如,以“TestIntegration”开头的测试类应该只在每晚构建中运行),您需要在 Maven 中重现它们。

But yeah, in general it means to take the existing functionality of a build, and reproduce that same functionality using Maven.

但是,是的,一般来说,这意味着采用构建的现有功能,并使用 Maven 重现相同的功能。

回答by PaulJWilliams

It means to reorganise the projects code and resources to conform to the maven model. This use of 'convention over configuration' allows the standard maven tools to operate on your codebase.

就是重新组织项目代码和资源,使其符合maven模型。这种“约定优于配置”的使用允许标准 Maven 工具在您的代码库上运行。

回答by E_X

In addition to what is said.

除了所说的。

One can always convert an existing java project to a maven project with eclipse IDE, m2eclipse plugin supports such feature or option, as follows: After installing m2eclipse plugin and restarting eclipse. Right click java project --? configure --? convert to maven

使用eclipse IDE可以随时将现有的java项目转换为maven项目,m2eclipse插件支持这样的功能或选项,如下: 安装m2eclipse插件并重启eclipse后。右键单击java项目--?配置 - ?转换为 Maven

You will have a generated pom to start with, almost always it needs modifications to match the projects dependencies and repositories if those dependencies aren't in the maven central repo.

您将有一个生成的 pom 开始,如果这些依赖项不在 maven 中央存储库中,它几乎总是需要修改以匹配项目依赖项和存储库。