Maven Add Jar Package dependency

Source: Internet
Author: User

MAVEN's stuff is used for a while, but each use is somewhat vague, so summarize it.

Currently the main use is in the control of the jar package

  principle :

Locally, specifying a folder, which is the Maven repository, MAVEN downloads the jar resources you need from the remote central repository to your local, then through Maven Association, tells the jar packages to be dependent on your project, avoids the need to copy the jar package into Lib, And the work of these jar packages is introduced through CLASSPATH.

  Advantages of Use :

    1. Easy to add a project-dependent jar package, for example, if you need to use SPRING-MVC, you must introduce SPRING-MVC and all of its associated jar packages into the project, sometimes different versions of the dependent jar packages are different, So you need to look at the description of the jar package to introduce the jar file that corresponds to the version number. It seems to be too painful. MAVEN, when you introduce the jar package, will introduce you to all the jar packages that it relies on, even if the repository doesn't have to be considered.
    2. Easy to control the version of the jar package, and the dependencies of each jar package. For example, when you use the spring framework, you may find different versions of the development process, and when you need to modify the version, it takes time and effort to copy the jar package to Lib, and the version number is modified directly in Maven's Pom file, and maven will help you modify the jar dependency of the project reference.

That's two reasons enough for you to choose MAVEN for the version management of the jar package. Of course, Maven can also compile your project projects into jar packages and put them into the repository for other projects to rely on. Other features that I haven't used yet, and later use to add.

  installation using :

Download maven, store in a fixed folder, and configure environment variables:%m2_home%\bin

CMD into the console, mvn-version, to see if the configuration was successful.

By default,maven has two levels of configuration information: User level, global level

  1. User level: Set only for one user, usually in ${user.home}/.m2/settings.xml. After Maven installs, the folder does not have this XML file, maven just uses the default configuration, can go to Maven's apache-maven-3.2.3\conf folder, Copy the settings.xml file to the above folder, and modify the appropriate configuration information.

  2. Global level: Used to set up all users on the machine, assuming they all use the same maven installer. It is usually set in ${maven.home}/conf/settings.xml.

Here you need to know when Maven and how to use these two configuration files to work:?????????????????????????????????????????????????????

  Configuration content: Only the local repository needs to be configured at this time.

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Settingsxmlns= "http://maven.apache.org/SETTINGS/1.0.0"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 xsi:schemalocation= "http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">5         <!--Configure the directory where the local repository resides -6     <localrepository>D:\install\other\apache-maven-3.2.3\repository</localrepository>7 </Settings>

This puts the remote warehouse under the D:\install\other\apache-maven-3.2.3\repository.

  MyEclipse combined with Maven:

MyEclipse need to specify the absolute path to MAVEN's installation directory on your local computer, the profile you need to use. Enter the Windows->preference,

Under the Installations tab, select the installation path for MAVEN.

Under the User Settings tab, select the path to the configuration file, you can specify a user-level profile, or you can specify a global-level profile.

  MyEclipse Create a MAVEN project and add Project dependencies:

The latest MyEclipse How many bugs, such as the 2013-in-debug variable value, the expression value can not be viewed, and so on, and so on, in the course of work, I choose MYECLIPSE10 for development, using MyEclipse to create the web Project and add Maven dependencies so that the created project can use MAVEN for version control of the jar package. As shown in the following:

  

Then, according to the project name and company name, name the repository and the version number.

This creates a new MAVEN project.

The project structure is as follows:

Add the dependent jar to the pom.xml.

  When added, if you find that the local repository does not have a corresponding jar package:

Rebuild index local repository, which forces maven to download the jar package from the central repository to the local repository

Use MyEclipse's Maven repository to reindex warehouses

On the local warehouse right-click: Rebuild Index

Second, under the Maven tab in preference, the update usersettings option in user settings, which forces maven to download the appropriate jar file to the central repository to the local

Externally introduced projects:

Externally introduced projects will find that some jar packages in the local repository do not exist. At this point on the project, right-click,

You may find that the jar package is not added to the local repository at this time, but you can see the pom file and the SHA1 file in the appropriate location in the local repository for the jar package, stating that the description of the jar pack has been placed in the repository, which is required in the Maven repository window. Rebuild index, you can also right-click under Windows->preference and then update usersettings under MAVEN's tab, and the jar package will be downloaded locally from the Remote central repository. This makes it possible to build the project.

Maven Add Jar Package dependency

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.