How to use Maven in my Java Project and Why?

前端 未结 7 517
臣服心动
臣服心动 2020-12-24 02:42

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 produc

相关标签:
7条回答
  • 2020-12-24 03:43

    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.

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

    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.


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


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

    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>
    

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

    0 讨论(0)
提交回复
热议问题