1 Download path for MAVEN package:
Http://maven.apache.org/download.html
Install Maven 2 maven to create a project Engineering architecture command
Enter Commond LINE,CD to a directory
MVN archetype:create-dgroupid=com.mycompany.app-dartifactid=my-webapp-darchetypeartifactid= Maven-archetype-webapp
CD to the project directory under My-webapp.
MVN Package
MVN Eclipse:eclipse
Open Eclipse, import. 3 maven Download the required Jar Package method
With MAVEN, the required jar packs can no longer be found and downloaded as usual, using the IDE to get it done, Maven uses a project dependency (Dependency) concept, which, as the saying goes, is that my project needs to use your jar bag, Just call my project dependent on your package, in other words, your jar bag is the dependency of my project.
So many people just use maven time, will be in addition to dependency when the fall, obviously I have the necessary jar on hand, it is not let me use, what reason, then is sulking, less patience, will say maven how how uncomfortable, in fact, If you understand some of MAVEN's mechanisms, some configuration and management processes, you'll find it really cool.
For the time being, I'm not talking about Maven's long concept (but I still have a lot of things I don't understand), so I'm going to introduce you to a simple search method that allows you to quickly find the dependency you need and configure it into your pom.xml.
The quickest way:
Google search: maven you need a jar package name repository
Like I'm going to do EJB, I'm looking for Jboss-j2ee.jar's dependency.
Just type it in Google.
Maven JBOSS-J2EE Repository
In the first of the results, you can find the following paragraph in the page
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-j2ee</artifactId>
<version>4.0.2</version>
</dependency>
You post the above code to the pom appropriate location of your MAVEN project, and then run Maven,maven will automatically download the required jar and related pom information, and you don't have to worry about it, MAVEN will help you download it and put it in the right place.
Let me give you a few more examples to familiarize you with how to search
I'm going to find Struts.jar below.
Enter in Google
MAVEN Struts Repository
You'll soon find the following code.
<dependency>
<groupId>struts</groupId>
<artifactId>struts</artifactId>
<version>1.2.9</version>
</dependency>
I'm still looking for hibernate.
In Google input
Maven Hibernate repository
In the results of the first record there are a lot of different hibernate links (because there are very items used hibernate well) we choose Org.hibernate, looks professional point, hehe
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
</dependency>
All right, SSH's not missing the middle s,spring.
Enter in Google
MAVEN Spring Repository
In the first result, we chose org.springframework this time,
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.5</version>
</dependency>
Other I will not one of the examples, we try, in fact, this method can solve most of the commonly used package dependency search, do not specifically remember those repository download station URL, but always this is informal practice, others want to better find the desired dependency, Still have to understand what Maven repository is, its local repository library concept, and how to build its own repository server (which I am not familiar with, here is not to say, people go to other places to find relevant information, lest I misled)
MAVEN's repository, plainly is dependency warehouse, it according to certain rules will dependency stored up for caching, if this machine repository can not find a dependency, It automatically finds other associated repository on the Internet and downloads it to the local area, so the next time it stops downloading elsewhere, it gets it directly from the local.
Where the local repository can be found.
Default Repository Address: The current user's private directory +. m2
If you set the Conf/setting.xml local repository attribute under the Maven directory, you are no longer the default repository address and use the address you specify.
Find the following paragraph, copy it, put it outside the comment, and change it to your own repository path.
<LOCALREPOSITORY>C:\MVN repository\</localrepository>
What rules does maven follow to store dependency?
Let's take hibernate as an example of how to cache a local repository when Maven runs and downloads to the desired dependency
Here's the hibernate dependency configuration.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
</dependency>
It is downloaded and will be stored to
%repository%\org\hibernate\hibernate\3.2.6.ga\hibernate-3.2.6.ga.jar
One of the%repository% is your local repository directory.
I do not know if you see it, it is according to your dependency GroupID + Artifactid + version, and then separated by dots, to create a folder, the last set up a folder as follows
|--org
|--hibernate
|--hibernate
|--3.2.6.ga
|--hibernate-3.2.6.ga.jar
Some people may ask how the name of the jar bag came, the careful person may have already observed, yes, is Artifactid + "-" + version + ". Jar".
Okay, let's follow this rule and find out where the other dependency are.
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>1.4.61</version>
</dependency>
We're going to go to your local repository directory and then go to the COM directory, go to the Google directory, go to the GWT directory, and go to the Gwt-servlet directory. Then enter the 1.4.61 directory, and then you can find a name Gwt-servlet-1.4.61.jar and some other documents. Let's try it. Note: When you first use this dependency, be sure to run maven, let it download to the required package, download successfully you can follow the steps above to find, or you can't find not to scold me, you have not downloaded words, certainly can not find the: ("
After you master this technique, there are many times you can according to the package path of the package, you touch its dependency, this is unknown, in short you know, find dependency will not be a problem, very simple things
At this time, there are some other users will ask questions, I want to use the jar bag is my own development, or friends, or netizens came, on the internet according to find, how to use them in maven? In fact, the method is certain, but also not difficult, is often used, I would like to briefly introduce a few methods:
The premise is that you must first write to the Pom inside, the organization as you write, artifact write your jar name, or casually write, version you also write what you want, such as
<dependency>
<groupId>com.mydomain.ooooo</groupId>
<artifactId>my-jar</artifactId>
<version>100.1.1</version>
</dependency>
First, use your IDE well.
Now the IDE is all about eclipse, or NetBeans, or JBuilder, and as far as I know, most people are now moving forward, and these Ides provide support for MAVEN, but usually you need to install Plug-ins to open and use Maven's projects, How to install the MAVEN plugin I will not introduce, everyone on the internet to find someone else to write the article it. After you have installed the plug-in, there will usually be a libraies directory, which lists your project to use the jar package, you right-click the Local has not been added to the jar package, select the local installation (manually install artifact), select your special jar bag, The IDE then automatically invokes the MAVEN plug-in to complete the installation configuration process, and the next time you don't do it again, because your local repository already have it.
Second, manually put the jar bag into the local repository inside
According to the previous MAVEN repository storage rules, you build your own directory, change the name of the jar, and cuff yourself, as
into your local repository directory.
Build a COM folder and point it in
Build another MyDomain folder and point it in.
Build another ooooo folder and point it in.
Build another My-jar folder and point it in.
Build another 100.1.1 folder and point it in.
Then rename your jar bag to My-jar-100.1.1.jar and put it in the 100.1.1 folder.
Then run your MAVEN project to see if it's going to build successfully, in fact, if the folder you made before is correct, the case is OK, or there are no other minor mistakes, your project can use your own jar bag normally.
Three, direct to http://repo1.maven.org/maven2/search
But this also need you know MAVEN repository store rules to know how to find on the site, find you have to write their own dependency configuration code, I do not often come here to find. But tastes, we choose the right one4 maven Common commands
MVN Compile
Compiling the main program source code does not compile the source code for the test directory. The first time you run, you will download the dependent dependencies, which can be more time-consuming.
MVN Test-compile
The test code is compiled, the target folder is generated after compile, the main program is compiled under classes, and the test program is placed under Test-classes.
MVN test
To run a unit test in an application
MVN site
Web site to generate project-related information
MVN clean
Clear the build results in the target directory
MVN Package
The jar file is generated from the project and is compiled and tested before being packaged.
MVN Install
Install the jar in the local Repository.
MVN Eclipse:eclipse
Generate Eclipse project files and package reference definitions, note that you need to make sure that you define classpath Variables:m2_repo, pointing to the local MAVEN class library directory.
5 configuring Maven in Eclipse
Join M2_repo
Enter Eclipse->preferences->java->build path->classpath variables, add m2_repo this variable, point to C:/Documents and Settings/username/.m2/repository, this path is the default Maven repository, and if you want to move somewhere else, you need to modify the maven\conf\setting.xml inside the localrepository.
Configure string substitution
By configuring string Subsitution We can use Eclipse's Lanuch to start maven instead of the Eclipse plug-in startup. First we'll tell Eclipse where Maven is. Configure Eclipse->preferences->run/debug->string subsitution, add mvn = d:/dotj_dev/tools/apache-maven-2.2.1/bin/ Mvn.bat.
Leave a: M2eclipse plugin, install maven
Http://wenku.baidu.com/view/fdf1220302020740be1e9bd3.html