且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在我的Java项目中使用Maven?为什么?

更新时间:2022-03-09 01:55:15

Maven用于管理构建,测试和部署过程.它可以将单元测试和集成测试分开,因此您仅在必要时运行它们,并减少构建时间.

Maven is used to manage the build, testing, and deployment processes. It can separate the unit tests and integration tests so you only run them when necessary and cut down on build time.

它也是一个依赖管理器,这意味着当您意识到项目的服务器部分需要apache commons-logging 1.0.4但客户端与0.7.9之后的任何内容发生冲突时,您只需添加几行到各自的pom.xml文件中,Maven会处理所有这些问题(下载,安装并跟踪这些依赖项的不同版本).

It is also a dependency manager, which means when you realize the server piece of your project needs apache commons-logging 1.0.4 but the client conflicts with anything past 0.7.9, you can just add a couple lines to the respective pom.xml files, and Maven handles all of that (downloading, installing, and keeping track of the different versions of those dependencies).

在执行当前任务之前,我并不相信,但是在将其用于大型企业应用程序2年之后,我绝对尊重Maven带来的好处.有很多在线资源,但是如果您要成为领导者并且真的不舒服,我建议您买一本书-

I was not a believer before my current task, but after 2 years using it for large enterprise applications, I definitely respect what Maven brings to the table. There are a lot of online resources but if you are going to be the lead on this and really feel uncomfortable, I recommend getting a book -- the O'Reilly one is helpful.

忘了提到一个Eclipse插件,它几乎可以轻松地与Eclipse一起使用: m2Eclipse .

Forgot to mention that there is an Eclipse plugin which makes it almost painless to use with Eclipse: m2Eclipse.

例如pom.xml段的第二次更新以回答OP问题:

Second update for example pom.xml segment to answer OP question:

您的pom.xml将包含XML代码,例如:

Your pom.xml will contain XML code such as:

<dependencies>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.0.4</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

这些是从中间Maven存储库(谷歌"maven nexus")下载的,或者您可以配置自己的其他存储库(例如用于自己的项目,或者如果没有Internet连接).

These are downloaded from the central Maven repository (google "maven nexus") or you can configure your own additional repositories (like for your own projects, or if you are not Internet-connected).