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

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文件夹)

7
又一次在HelloFriend文件夹下运行命令mvnpackage

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R1enVvcXVhbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

3.将maven项目jar纳入maven仓库,Mave项目依赖另外一个Maven项目的案例的更多相关文章

  1. maven自定义jar到本地仓库

    Apache Maven为项目构建提供了绝佳的解决方案,其本地仓库中缓存了远程代理仓库或中央仓库中的资源,从而提高网络资源使用效率,很好很强大!  但是并非所有资源都可以根据GroupId.Artif ...

  2. Maven - 实例-2-使用本地仓库中的依赖包

    Maven引入构建包的流程 执行mvn compile命令编译源代码,如果编译过程中需要用到其他的包, maven将会在pom.xml文件中查找是否引入该依赖包的坐标. 示例: <depende ...

  3. maven安装jar到本地仓库

    class12.jar这个东西在中央仓库里没有,所以,cmd到oracle\product\10.2.0\db_1\jdbc\lib路径下,mvn install 就好了(发布第三方jar到本地库) ...

  4. 使用maven安装jar到本地仓库

    mvn install:install-file "-DgroupId={安装的jar包的groupid,可以随意起名}" "-DartifactId={安装jar包的I ...

  5. maven将Jar安装进仓库

    mvn install:install-file -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.4 -Dpac ...

  6. maven打包jar到本地仓库

    1.执行如下命令 mvn install:install-file -Dfile=guava-28.2-jre.jar -DgroupId=com.google.guava -DartifactId= ...

  7. maven管理jar,pom.xml导入spring依赖

    <properties> <junit.version>4.12</junit.version> <spring.version>4.3.9.RELEA ...

  8. maven 将jar包推送到自己本机的maven库

    mvn install:install-file -DgroupId=com.wdcloud.sdk -DartifactId=front-category-signed -Dversion=1.0. ...

  9. 【源码项目+解析】C语言/C++开发,打造一个小项目扫雷小游戏!

    一直说写个几百行的小项目,于是我写了一个控制台的扫雷,没有想到精简完了代码才200行左右,不过考虑到这是我精简过后的,浓缩才是精华嘛,我就发出来大家一起学习啦,看到程序跑起来能玩,感觉还是蛮有成就感的 ...

随机推荐

  1. 关于apache access log 统计的那些事儿

    统计APACHE ACCESS.LOG IP访问记录 可以根据自己的需要,统计很多,每个IP访问多少个页面等等! cat access.log-20090904 |awk '{print $3}'|s ...

  2. CPP-基础:文字常量区

    内存不可写 char* 先看一个例子 ///////////// //代码1 #include <string> main() { char *buf = "good morni ...

  3. python爬虫---从零开始(三)Requests库

    1,什么是Requests库 Requests是用python语言编写,基于urllib,采用Apache2 Licensed 开源协议的HTTP库. 它比urllib更加方便,可以节约我们大量的工作 ...

  4. vmware linux虚拟机与本地物理机共享文件夹

    cd /mnt/hgfs 使用Vmware安装了linux虚拟机后,开发时,为了方便文件的传输等,因此需要使用共享文件夹,减少工作量.共享文件夹需要用到vmware提供的vmware tools工具, ...

  5. (14) openssl x509(签署和自签署)

    主要用于输出证书信息,也能够签署证书请求文件.自签署.转换证书格式等. openssl x509工具不会使用openssl配置文件中的设定,而是完全需要自行设定或者使用该伪命令的默认值,它就像是一个完 ...

  6. 文本三剑客之awk

    awk和流编辑器sed在工作原理和用法上有很多类似之处,它们都是检查输入数据中的行是否匹配指定的模式,如果匹配成功就对匹配的行执行相应的操作,重复这个过程直到所有的输入数据都被处理完,因此awk和se ...

  7. 《算法导论》— Chapter 11 散列表

    1 序 在很多应用中,都要用到一种动态集合结构,它仅支持INSERT.SEARCH以及DELETE三种字典操作.例如计算机程序设计语言的编译程序需要维护一个符号表,其中元素的关键字为任意字符串,与语言 ...

  8. C#中如何使用正则表达式

    [草稿版本,谨慎阅读] 参考文档:正则表达式30分钟入门教程 如需系统学习正则表达式内容,请移步上述教程. 正则表达式按照指定的规则来匹配字符或字符串.'.' ' \b' ' \d'等等被称为是正则表 ...

  9. PHP 小方法之 获取中文字的首字母

    public function getFirstCharter($str) { if (empty($str)) { return ''; } $fchar = ord($str{0}); if ($ ...

  10. js正则替换十六进制

    var re=/\x62/;//没有0,也没有分号。alert(re.test("blue"));  //output "true" 需要使用< 如需显示 ...