Road to architects 19th Day using MAVEN to build spring project

Source: Internet
Author: User
Tags prepare log4j

First, the preface

The last time I uploaded the project, some people themselves through the Spring3,struts1.3,hibernate3 download package to assemble the jar package to the project Web-inf\lib directory. Some of the Alpha_lib package I uploaded to the inside of the jar file a brain copy to the project Web-inf\lib directory down.

Sometimes there will be less bag, classnotfound such a mistake, or some because of the lack of the package also caused by a variety of inexplicable wonderful mistakes, oh, is not enough to toss ah?

Have tasted the pain, just know the bitter! So do we have a better way, say:

I got off the blogger project, made an order, or build in Eclipse, and the project needed a jar file that automatically ran into my project?

Some! This is maven!!!.

So today we're going to talk about using MAVEN to build our project and how to run a Web project in eclipse that was built by MAVEN (the information on the Internet is incomplete, so the individual sums up the experience and shares it with everyone).

Ii. traditional construction and use of MAVEN construction

Traditional mode:

The construction of this project in the 18th Day is the construction of a standard traditional model, which is accepted by most people.

It puts all the jar files in the engineering Web-inf\lib directory and uses Ant to package and publish them. The benefits of doing so are simple, intuitive, and straightforward. The downside is that people who build the project have a lot of experience, or they can cause all sorts of bizarre bugs that occur at the time of the installation or at runtime because of fewer jar files or duplicate jar files.

Some people like to download the spring3.1 and struts1.3 download package in the Lib directory all the jars regardless of 3,721 copy to the project Web-inf\lib directory, there is a hint to cover him also select "All".

I have seen a project, not a few jsp,class, engineering up to 287MB, of which 286MB is a jar file, which is log4j-1.3.8.jar,log4j-1.4.2.jar such a duplicate jar file exists.

With junit3.8 unexpectedly also found that the project has junit4.x bag ... Dizzy Ah.

Maven mode:

And when you build a project with Maven, it's not going to happen, and beginners can think of maven as an "automatic charter." How to explain it, for instance:

You want to load A.jar, but A.jar relies on B.jar, and B.jar relies on C.jar and D.jar, if only 2, 3-level dependency builders can remember, but if this dependency reaches 6 levels, More than 7, then according to the traditional construction mode when you find that a directory has Abcdefghijk these jar files, you are usually in order to avoid error is always an old brain to copy all the jar files into the project, right?

But the actual jar files are only A.jar,b.jar, C.jar is what you need.

And Maven does this is its specialty, when you tell maven you want to download the A.jar file, it will find that A.jar rely on other jar files, it will be your designated jar file and related dependent files all take down, not to take more (90% cases).

Just like you want to take org.springframework.web.struts-3.0.0.release.jar this file, but in fact it still needs to use asm,collection, bean-util etc., then All you have to do is tell Maven that I'm going to get org.springframework.web.struts-3.0.0.release.jar. This file, other dependent related jar packs will automatically "download" to your project. So when I take When Maven goes back to building that 286MB project, all of the functionality of the project is not affected, relying on MAVEN's automatic reliance on jar packs the entire project has shrunk from 286MB to 21MB, haha ... Oh, man, that's the old gang!

Iii. use of Maven

3.1 Pre-use preparation steps

Prepare Step One:

Please download the latest maven2, such as: apache-maven-3.0.3-bin.tar.gz (I am using this version), I also put it in my csdn "resources".

Prepare Step Two:

Make sure your eclipse is WTP and upgrades Mavenfor Eclipse, which has the MAVEN option in your eclipse->window->preference:

The best thing to do is to go to Eclipse's website and download a ECLIPSEWTP version (http://download.eclipse.org/webtools/downloads/), and then upgrade, which may be a long upgrade process, 5-6 hours is also possible (the author's home speed is 20MB fiber). But after the first level, the next week nothing to let your eclipse to update is also necessary, it must be the thing you eat after the guy, to maintain it is always the latest version is a good habit.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.