Maven在理论和实践中做了什么?什么时候值得使用它? [英] What does Maven do, in theory and in practice? When is it worth to use it?

查看:131
本文介绍了Maven在理论和实践中做了什么?什么时候值得使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我即将开始一个Java项目只是为了练习。我读过关于Maven的内容,但我实际上并不了解它何时被使用。

I am about to start a Java project just for practice. I've read about Maven, but I don't actually understand when it is meant to be used.

你能给我一些实用的建议吗? Maven有很多帮助吗? Maven为我的项目实际做了什么?

Can you give me some practical tips? Does Maven help a lot? What does Maven actually do for my project?

推荐答案

它的作用

Maven是一个构建管理工具,它用于定义如何将 .java 文件编译为。 class ,打包成 .jar (或 .war .ear )文件,(前/后)用工具处理,管理 CLASSPATH ,以及构建项目所需的所有其他类型的任务。它类似于 Apache Ant Gradle 或在C / C ++中 Makefiles ,但它试图完全独立,你不需要任何额外的工具或脚本,通过结合其他常见的任务,如下载和安装必要的库等。

Maven is a "build management tool", it is for defining how your .java files get compiled to .class, packaged into .jar (or .war or .ear) files, (pre/post)processed with tools, managing your CLASSPATH, and all others sorts of tasks that are required to build your project. It is similar to Apache Ant or Gradle or Makefiles in C/C++, but it attempts to be completely self-contained in it that you shouldn't need any additional tools or scripts by incorporating other common tasks like downloading & installing necessary libraries etc.

它也是围绕构建可移植性主题设计的,因此您不会因为使用相同的构建脚本而获得相同的代码在一台计算机上但不在另一台计算机上(这是一个已知的问题,我们有Windows 98机器的虚拟机,因为我们无法在其他任何地方编译我们的Delphi应用程序)。因此,它也是在使用不同IDE的人之间处理项目的最佳方式,因为IDE生成的Ant脚本难以导入到其他IDE中,但是现在所有IDE都理解并支持Maven( IntelliJ Eclipse NetBeans )。即使你最终不喜欢Maven,它最终也成为所有其他现代构建工具的参考点。

It is also designed around the "build portability" theme, so that you don't get issues as having the same code with the same buildscript working on one computer but not on another one (this is a known issue, we have VMs of Windows 98 machines since we couldn't get some of our Delphi applications compiling anywhere else). Because of this, it is also the best way to work on a project between people who use different IDEs since IDE-generated Ant scripts are hard to import into other IDEs, but all IDEs nowadays understand and support Maven (IntelliJ, Eclipse, and NetBeans). Even if you don't end up liking Maven, it ends up being the point of reference for all other modern builds tools.

为什么要使用它

Maven有三件事非常很好。

There are three things about Maven that are very nice.


  1. Maven将(在您宣布使用哪些库之后)下载您使用的所有库 他们使用的库为你自动。这非常好,并且使得处理大量库变得非常容易。这可以避免依赖地狱。它类似于Apache Ant的常春藤

  1. Maven will (after you declare which ones you are using) download all the libraries that you use and the libraries that they use for you automatically. This is very nice, and makes dealing with lots of libraries ridiculously easy. This lets you avoid "dependency hell". It is similar to Apache Ant's Ivy.

它使用约定优于配置,因此默认情况下您不需要定义您要执行的任务。您不需要像在Ant或Makefile中那样编写compile,test,package或clean步骤。只需将文件放在Maven所期望的位置,它就可以解决问题。

It uses "Convention over Configuration" so that by default you don't need to define the tasks you want to do. You don't need to write a "compile", "test", "package", or "clean" step like you would have to do in Ant or a Makefile. Just put the files in the places in which Maven expects them and it should work off of the bat.

Maven还有很多很好的插件可供你使用可以安装,将处理许多例行任务从使用JAXB从XSD架构生成Java类 测量Cobertura的测试覆盖率。只需将它们添加到 pom.xml 中,它们就会与您想要执行的其他操作集成。

Maven also has lots of nice plug-ins that you can install that will handle many routine tasks from generating Java classes from an XSD schema using JAXB to measuring test coverage with Cobertura. Just add them to your pom.xml and they will integrate with everything else you want to do.

初始学习曲线很陡,但(几乎)每个专业Java开发人员都使用Maven或希望他们这样做。你应该在每个项目中使用Maven,但是如果你需要一段时间来习惯它并且有时你希望你可以手动做事,那就不会感到惊讶,因为学习新东西有时会受到伤害。但是,一旦你真正习惯了Maven,你会发现构建管理几乎没有时间。

The initial learning curve is steep, but (nearly) every professional Java developer uses Maven or wishes they did. You should use Maven on every project although don't be surprised if it takes you a while to get used to it and that sometimes you wish you could just do things manually, since learning something new sometimes hurts. However, once you truly get used to Maven you will find that build management takes almost no time at all.

如何开始

最好的起点是 Maven in 5 Minutes 。它将帮助您开始准备一个项目,以便您编写所有必要的文件和文件夹设置(是的,我建议使用快速入门原型,至少在开始时)。

The best place to start is "Maven in 5 Minutes". It will get you start with a project ready for you to code in with all the necessary files and folders set-up (yes, I recommend using the quickstart archetype, at least at first).

开始使用后,您需要更好地了解该工具的使用方式。为此使用Maven更好地构建是了解其工作原理的最彻底的地方,但是, Maven:The Complete Reference 是更新的。阅读第一个以便理解,然后使用第二个作为参考。

After you get started you'll want a better understanding over how the tool is intended to be used. For that "Better Builds with Maven" is the most thorough place to understand the guts of how it works, however, "Maven: The Complete Reference" is more up-to-date. Read the first one for understanding, but then use the second one for reference.

这篇关于Maven在理论和实践中做了什么?什么时候值得使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆