How Maven projects refer to other projects/or jar packages __maven

Source: Internet
Author: User
Tags aliyun

Practice:

I am Wen Haojan:

Now more and more projects are using MAVEN to manage jar packs, and what I'm saying here is how maven references the local MAVEN project.

A project is downloaded from SVN, deleted locally (just delete in the work environment, do not delete files), import the MAVEN project through Eclipse, right-click the project, select Maven, and choose Update Project.

A project's jar package is downloaded from the MAVEN server to the local.

My understanding of maven.

MAVEN manages the jar package, or it can be said to manage the project. All the MAVEN projects, all with a pom.xml file,

All the code is as follows.

<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:s chemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < Modelversion>4.0.0</modelversion> <groupId>com.tujia</groupId> <artifactid>file-serve R</artifactid> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <
                build> <finalName>file-server</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin<
                    /artifactid> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configurat Ion> </plugin> </plugins> </build> <properties> <project.build.sourceencoding>utf-8</project.b uild.sourceencoding> </properties> <dependencies> <dependency> <grou Pid>junit</groupid> <artifactId>junit</artifactId> <version>4.11</ve 
            rsion> </dependency> <dependency> <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId> <version>RELEASE</version> </dependency> <dependency> <groupId>org.quartz-scheduler</groupId> <a Rtifactid>quartz-jobs</artifactid> <version>2.2.1</version> </dependency> < Dependency> <groupId>org.springframework</groupId> <artifactid>spring-context
    </artifactId>        <version>3.2.8.RELEASE</version> </dependency> <dependency> &
            Lt;groupid>org.springframework</groupid> <artifactId>spring-context-support</artifactId> <version>3.2.8.RELEASE</version> </dependency> <dependency> < Groupid>com.google.code.gson</groupid> <artifactId>gson</artifactId> <vers ion>2.2.4</version> </dependency> <dependency> <groupid>jstl</gr Oupid> <artifactId>jstl</artifactId> <version>1.2</version> ;/dependency> <dependency> <groupId>javax.servlet</groupId> <artif Actid>jsp-api</artifactid> <version>2.1</version> </dependency>
        ;d ependency>    <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.logback-extensions</groupId> <artifactid>lo
                Gback-ext-spring</artifactid> <version>0.1.1</version> <exclusions> <exclusion> <groupId>ch.qos.logback</groupId> <arti factid>logback-classic</artifactid> </exclusion> </exclusions> &L t;/dependency> <dependency> <groupId>ch.qos.logback</groupId> <art 
        Ifactid>logback-classic</artifactid> <version>1.1.2</version> </dependency> <dependency&Gt
            <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> <version>1.9.13</version> </dependency> <dependency> <group
            Id>org.codehaus.jackson</groupid> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.13</version> </dependency> <dependency> <groupid>o Rg.apache.tiles</groupid> <artifactId>tiles-core</artifactId> <version>2.2 .2</version> <exclusions> <exclusion> <groupid>org .slf4j</groupid> <artifactId>jcl-over-slf4j</artifactId> </exclus ion> </exclusions> </dependency> <dependency> <groupId> Org.apacHe.tiles</groupid> <artifactId>tiles-api</artifactId> <version>2.2.2</v ersion> </dependency> <dependency> <groupid>org.apache.tiles</groupid&
            Gt <artifactId>tiles-jsp</artifactId> <version>2.2.2</version> </dependency&gt
  		; <dependency> <groupId>com.tujia</groupId> <artifactid>tu-search-client</artifacti d> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <group Id>com.tujia</groupid> <artifactId>tu-login</artifactId> <version>0.0.1-snapshot</ version> </dependency> <dependency> <groupId>com.aliyun.oss</groupId> <artif actid>aliyun-sdk-oss</artifactid> <version>2.0.2</version> </dependency> </depende ncIes> </project> 

I think the Pom.xml file is divided into these parts,

1, the head, all the configuration files have this.

<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
    < Modelversion>4.0.0</modelversion>
2, the current project information. For example, version, name, packing format, and so on.
	<groupId>com.tujia</groupId>
    <artifactId>file-server</artifactId>
	<version >0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
3. Information about the current project in Maven.
<build>
    	<finalName>file-server</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactid>maven-compiler-plugin</ artifactid>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</ source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </ Plugins>
    </build>
4, the rest is the part four, referenced by other jar packages.


This is maven in a project.

If one of your MAVEN projects wants to refer to other local projects, you need to put the second part of the referenced project, the Pom.xml file, into the pom that references the project.

The format is as follows.

<dependency>
    These three are the second part of the referenced project.    <groupId>com.tujia</groupId>
<pre name= "code" class= "HTML" >    these three are the second part of the referenced project. <span style= "font-family:arial, Helvetica, Sans-serif;" >       <artifactId>tu-login</artifactId></span>
    These three are the second part of the referenced project.  <span style= "font-family:arial, Helvetica, Sans-serif;" >    <version>0.0.1-SNAPSHOT</version></span>
</dependency>

If you need to refer to a jar package in your project, write it just as you did earlier. You can use compression software such as good pressure to open the jar package, some jar packages will have pom.xml information. When the item is updated, the jar package is downloaded to your computer.

This is the path saved after downloading my local jar pack.

C:\Users\whr-pc\.m2\repository, generally, are placed under the. M2 folder.

Then a layer of open, you will find the jar package used.

If there is an error importing a jar package, the hint cannot find the jar package, which needs to be manually downloaded to the jar package and put to the local. m2/. /.. Below.

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.