码迷,mamicode.com
首页 > 编程语言 > 详细

3.将maven项目jar纳入maven仓库,Mave项目依赖另外一个Maven项目的案例

时间:2014-10-18 09:52:29      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   java   sp   文件   



1 若想让maven项目依赖另外一个maven项目,被依赖的项目要在maven仓库中有相应的jar包,所以要对依赖的项目执行mvninstall命令。

bubuko.com,布布扣

2 新建第二个项目模块HelloFriend目录及约定的目录结构

HelloFriend

 --src

 -----main

 ----------java

 ----------resources

 -----test

 ---------java

 ---------resources

 --pom.xml

3 在项目HelloFriend根目录建立pom.xml

<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>cn.toto.maven</groupId>

  <artifactId>HelloFriend</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <name>HelloFriend</name>

 

         <dependencies>

                   <dependency>

                            <groupId>junit</groupId>

                            <artifactId>junit</artifactId>

                            <version>4.9</version>

                            <scope>test</scope>

                   </dependency>                 

                  

                   <dependency>

                            <groupId>cn.toto.maven</groupId>

                            <artifactId>Hello</artifactId>

                            <version>0.0.1-SNAPSHOT</version>

                            <scope>compile</scope>

                   </dependency>                 

                  

         </dependencies>

</project>

4 src/main/java/cn/toto/maven目录下新建文件HelloFriend.java文件

package cn.toto.maven;

 

import cn.toto.maven.Hello;

 

public class HelloFriend {

 

         public String sayHelloToFriend(String name){

                  

                   Hello hello = new Hello();

                   String str = hello.sayHello(name)+" I am "+this.getMyName();

                   System.out.println(str);

                   return str;

         }

        

         public String getMyName(){

                   return "John";

         }

 

}

5 /src/test/java/cn/toto/maven目录下新建测试文件HelloFriendTest.java

package cn.toto.maven;

 

import static junit.framework.Assert.assertEquals;

 

import org.junit.Test;

 

import cn.toto.maven.Hello;

 

 

public class HelloFriendTest {

         @Test

         public void tesHelloFriend(){

                  

                   HelloFriend helloFriend = new HelloFriend();

                   String results = helloFriend.sayHelloToFriend("tuzuoquan");

                   assertEquals("Hello tuzuoquan! I am John",results);             

 

         }

}

6 HelloFriend目录下执行命令mvn命令(注意到HelloFriend文件夹)

bubuko.com,布布扣

7 重新在HelloFriend目录下执行命令mvnpackage

 bubuko.com,布布扣

3.将maven项目jar纳入maven仓库,Mave项目依赖另外一个Maven项目的案例

标签:style   blog   http   color   io   ar   java   sp   文件   

原文地址:http://blog.csdn.net/tototuzuoquan/article/details/40208233

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!