如何在我的Java项目中使用Maven?为什么? [英] How to use Maven in my Java Project and Why?

查看:126
本文介绍了如何在我的Java项目中使用Maven?为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚 Maven 的使用,并且我收到了许多描述其功能和用途的文章.但是我只是不能从生产力的角度理解Maven的实际使用.

I am trying to figure out the use of Maven and I got many articles describing its features and uses. But I am just not able to understand the actual use of Maven from productivity standpoint.

在学校项目中,我习惯于在Eclipse中创建一个新的Java项目,编写代码,创建一个.war(如果基于Web),然后将代码粘贴到Tomcat的webapps文件夹中,然后启动服务器!

From what I am used to in our school projects was just create a new Java project in Eclipse, write your Code, create a .war (if web-based) and paste the code to the webapps folder of Tomcat and start the server!

所以

  1. Maven在哪里出现?我已经使用过Ant,并且了解Ants标准化构建过程的好处.但是为什么我们需要Maven形式的高级Ant?

  1. Where does Maven come into picture? I have used Ant and I understand Ants benefit of a standardized build process. But why do we need an advanced Ant in form of Maven?

无论如何,我都需要使用它,所以我应该从哪里开始-基本流程,一些不错的教程?

In any case, I need to use it, so where do I get started - basic flow, some good tutorials?

谢谢

推荐答案

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).

这篇关于如何在我的Java项目中使用Maven?为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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