maven常用的构建命令

一 常用mvn命令
mvn -v:查看版本
mvn compile:编译项目
mvn test:测试
mvn package:打包
mvn clean:删除target目录
mvn install:安装jar包到本地仓库中
 
二 构建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"?>
xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0
    <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] ------------------------------------------------------------------------

猜你喜欢

转载自cakin24.iteye.com/blog/2393038
今日推荐