maven常用的构建命令及实战

一 常用mvn命令

  • mvn -v:查看版本
  • mvn compile:编译项目
  • mvn test:测试
  • mvn package:打包
  • mvn clean:删除target目录
  • mvn install:安装jar包到本地仓库中

Maven命令的基本格式:

mvn <plugin-prexif>:<goal> -D<属性名>=<属性值> ...

Maven命令的插件格式:

mvn <plugin-group-id>:<plugin-artifact-id>[:plugin-version]:<goal>

二 构建maven02项目来引用hellomaven项目的jar包

1 maven02项目的主程序

package com.cakin24.maven02.util;
import com.cakin24.maven01.model.HelloWorld;
public class Speak{
    public String sayHi(){
        return new HelloWorld().sayHello();
    }
}

2 maven02项目的测试程序

package com.cakin24.maven02.util;
import org.junit.*;
import org.junit.Assert.*;
public class SpeakTest{
    @Test
    public void testsayHi(){
        Assert.assertEquals("Hello World!",new Speak().sayHi());
    }
}

3、pom.xml程序

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">;
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.cakin24.maven02</groupId>
    <artifactId>maven02-model02</artifactId>
    <version>0.0.1SNAPSHOT</version>
    <dependencies>
        <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.10</version>
        </dependency>
        <dependency>
                <groupId>com.cakin24.maven01</groupId>
                <artifactId>maven01-model</artifactId>
                <version>0.0.1SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

三 项目测试

1、安装maven01到本地仓库

F:\java\mavencode\maven01>mvn install

2、测试maven02是否正常运行

F:\java\mavencode\maven02>mvn test
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.cakin24.maven02:maven02-model02:jar:0.0.1SNAPSHOT
[WARNING] 'version' uses an unsupported snapshot version format, should be '*-SNAPSHOT' instead. @ line 9, column 11
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven02-model02 0.0.1SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven02-model02 ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory F:\java\mavencode\maven02\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven02-model02 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven02-model02 ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory F:\java\mavencode\maven02\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven02-model02 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to F:\java\mavencode\maven02\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven02-model02 ---
[INFO] Surefire report directory: F:\java\mavencode\maven02\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.cakin24.maven02.util.SpeakTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.142 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.193 s
[INFO] Finished at: 2017-09-09T19:18:27+08:00
[INFO] Final Memory: 12M/161M
[INFO] ------------------------------------------------------------------------

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值