Maven Dependency module Eclipse

Source: Internet
Author: User

Sometimes people just make a cheap thing come back every day to study is no result, but in the company firm research that results to see me is such a hehe.

Maven is based on the Project object Model (POM), which can be used to manage project construction, reporting, and documentation software through a small description of the information Project Management Tools .

: http://maven.apache.org.

The first thing to do is to use Maven under Eclipse, but it's not too difficult to integrate with eclipse, except that the warehouse is under the C drive. Here's a look at how to use MAVEN with dependent modules.

First download maven to extract your favorite drive letter.

Open your most familiar eclipse below to configure the Maven you just unzipped.

Configure the Setting.xml configuration file configuration to the local library.

Then the basic configuration operation is over. Here's how to create a maven project under Eclipse.

The above quick One is the Java project that you want to write SE code webapp is a Web project.

I have built 7 projects here. 3 of them are taken out for example.

First look at setting this project I will configure the jar to be used. Pom.xml as follows:

<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> <groupid>me.send </groupid> <artifactid>setting.configuration</artifactid> <version>0.0.1- snapshot</version> <name>setting.configuration</name> <url>http:// maven.apache.org</url>  <dependencies>  <dependency>    <groupId>junit</groupId>   <artifactId>junit</artifactId>    <version>3.8.1</version>   <scope>test</scope>  </ dependency>  <!-- mysql -->        <!- - mysql jdbc --> &nbSp;      <dependency>      <groupid> Mysql</groupid>      <artifactid>mysql-connector-java</artifactid >      <version>5.1.30</version>  </dependency>     <!-- mybatis  -->  <dependency>    <groupId>org.mybatis</groupId>   <artifactId>mybatis</artifactId>    <version>3.1.1</version>  </dependency>    <!--  mybatis - spring  -->  <dependency>   <groupid >org.mybatis</groupId>   <artifactId>mybatis-spring</artifactId>    <version>1.1.1</version>  </dependency>         &nBsp;</dependencies>  <packaging>pom</packaging>   <modules>   <module&gt, .... /produce.service</module>  <module&gt, .... /produce.client</module> </modules></project>

Module is about what you want to provide to other projects using the 2 projects that I have provided to service client on this side.

Dependency this everyone knows is to use the other framework of the Internet to provide if you do not know how to write can be directly in

http://mvnrepository.com/Direct search on this site. The full wording of this file is shown above.

Below is a look at the service's Pom file.

 <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> <artifactId> produce.service</artifactid> <name>produce.service</name> <url>http:// maven.apache.org</url> <properties>  <project.build.sourceencoding>utf-8</ Project.build.sourceencoding> </properties> <dependencies>  <dependency >   <groupid>junit</groupid>   <artifactid>junit</ artifactid>   <version>3.8.1</version>   <scope>test</ scope>  </dependency>   </dependencies> <!--  Add the following   Project Reference &NBSP;--&GT;&NBSP;&NBSP;&LT;PARENT&GT;&Nbsp; <groupid>me.send</groupid>  <artifactid>setting.configuration</ artifactid>  <version>0.0.1-snapshot</version> </parent>  < Packaging>jar</packaging> </project>

 

This is primarily a jar using the setting project see here we don't need to configure dependency of course the following packaging has also become a jar stating that this is to generate the jar file.

Look at the Pom file for the last client project

 <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> <artifactId> produce.client</artifactid> <name>produce.client</name> <url>http:// maven.apache.org</url> <properties>  <project.build.sourceencoding>utf-8</ Project.build.sourceencoding> </properties> <dependencies>  <dependency >   <groupid>junit</groupid>   <artifactid>junit</ artifactid>   <version>3.8.1</version>   <scope>test</ scope>  </dependency>    <dependency>               <groupid>me.send</groupid>               <artifactId>produce.service</artifactId>               <version>0.0.1-SNAPSHOT</version>             <scope>compile</scope>         </dependency>   </dependencies>   <parent>  <groupId>me.send</groupId>  <artifactId> setting.configuration</artifactid>  <version>0.0.1-snapshot</version> </ Parent>  <packaging>jar</packaging> </project>

 

This way I'm going to use setting the following Jar also uses all the code under the Service project I configured a parent tag and dependency . In this way, the code you write under the service can be called directly in the client project without having to copy it.

The advantage is that you write a direct reference to the code without having to copy the package name as before and create a new package or something. The sub-module management of the project is not much more cool and there is a jar you directly write Pom do not need to download. Another project is to use the jar directly referencing this project to not need to copy the code below the POM. Did you feel cool?

Here I wrote a code test that is possible to see where the callout is. There is nothing to say that can be commented on below.

Maven Dependency module Eclipse

Related Article

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.