Maven - 实例-1-手工创建Maven项目
1- 根据包结构创建maven项目目录
TestMaven
- src
- src/main/java/anliven/testmaven01/HelloMaven.java
- src/test/java/anliven/testmanven01/HelloMavenTest.java
- pom.xml
2- 示例代码和pom文件
<groupId></groupId> :项目的包名
<artifactId></artifactId> : 模块名
<version></version> : 版本,遵循Maven版本管理规范
HelloMaven.java
package anliven.testmaven01;
public class HelloMaven {
public String sayHello() {
return "Hello Maven!";
}
}
HelloMavenTest.java
package anliven.testmaven01;
import org.junit.*;
import org.junit.Assert.*;
public class HelloMavenTest {
@Test
public void testMaven() {
System.out.println("Run test!");
Assert.assertEquals("Hello Maven!", new HelloMaven().sayHello());
}
}
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>anliven.testmaven01</groupId>
<artifactId>testmaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
</project>
3- 运行mvn compile
如果是第一次运行mvn compile等命令时,将会下载很多的第三方和maven所依赖的jar包。
在Maven项目根目录下,默认生成target目录:
target 构建过程中的默认生成的临时目录
target/classes/ 存放src/main/java目录下源文件编译出来的字节码文件(.class)
target/maven-status/
guowli@5CG450158J MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven
$ mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building testmaven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ testmaven ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Anliven-Running\Zen\EclipseProjects\TestMaven\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ testmaven ---
[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 D:\Anliven-Running\Zen\EclipseProjects\TestMaven\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.064 s
[INFO] Finished at: 2017-10-20T10:56:12+08:00
[INFO] Final Memory: 15M/292M
[INFO] ------------------------------------------------------------------------
guowli@5CG450158J MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven
$ ls -l
total 1
-rw-r--r-- 1 guowli 1049089 561 Oct 19 17:44 pom.xml
drwxr-xr-x 1 guowli 1049089 0 Oct 19 13:21 src/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 10:56 target/
guowli@5CG450158J MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven
$ ls -l target/
total 0
drwxr-xr-x 1 guowli 1049089 0 Oct 20 10:56 classes/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 10:56 maven-status/
guowli@5CG450158J MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven
$ls -l target/classes/anliven/testmaven01/HelloMaven.class
-rw-r--r-- 1 guowli 1049089 406 Oct 20 10:56 target/classes/anliven/testmaven01/HelloMaven.class
4- 运行mvn test
生成如下目录:
target/surefire-reports/ 存放生成的测试报告
target/test-classes/ 存放src/test/java目录下源文件编译出来的字节码文件(.class)
guowli@5CG450158J MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven
$ ls -l target/
total 0
drwxr-xr-x 1 guowli 1049089 0 Oct 20 10:56 classes/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 10:56 maven-status/
guowli@5CG450158J MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven
$ mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building testmaven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ testmaven ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Anliven-Running\Zen\EclipseProjects\TestMaven\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ testmaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ testmaven ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Anliven-Running\Zen\EclipseProjects\TestMaven\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ testmaven ---
[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 D:\Anliven-Running\Zen\EclipseProjects\TestMaven\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ testmaven ---
[INFO] Surefire report directory: D:\Anliven-Running\Zen\EclipseProjects\TestMaven\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running anliven.testmaven01.HelloMavenTest
Run test!
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.064 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.286 s
[INFO] Finished at: 2017-10-20T11:01:06+08:00
[INFO] Final Memory: 16M/291M
[INFO] ------------------------------------------------------------------------
guowli@5CG450158J MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven
$ ls -l target/
total 0
drwxr-xr-x 1 guowli 1049089 0 Oct 20 10:56 classes/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 10:56 maven-status/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 11:01 surefire-reports/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 11:01 test-classes/
guowli@5CG450158J MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven
$ ls -l target/surefire-reports/
total 9
-rw-r--r-- 1 guowli 1049089 282 Oct 20 11:01 anliven.testmaven01.HelloMavenTest.txt
-rw-r--r-- 1 guowli 1049089 6398 Oct 20 11:01 TEST-anliven.testmaven01.HelloMavenTest.xml
5- 运行mvn package
生成如下目录及文件:
target/maven-archiver/
target/xxx-y.y.y-zzz.jar 生成的jar包
guowli@5CG450158J MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven
$ ls -l target/
total 0
drwxr-xr-x 1 guowli 1049089 0 Oct 20 10:56 classes/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 10:56 maven-status/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 11:01 surefire-reports/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 11:01 test-classes/
guowli@5CG450158J MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven
$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building testmaven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ testmaven ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Anliven-Running\Zen\EclipseProjects\TestMaven\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ testmaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ testmaven ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Anliven-Running\Zen\EclipseProjects\TestMaven\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ testmaven ---
[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 D:\Anliven-Running\Zen\EclipseProjects\TestMaven\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ testmaven ---
[INFO] Surefire report directory: D:\Anliven-Running\Zen\EclipseProjects\TestMaven\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running anliven.testmaven01.HelloMavenTest
Run test!
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.065 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ testmaven ---
[INFO] Building jar: D:\Anliven-Running\Zen\EclipseProjects\TestMaven\target\testmaven-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.437 s
[INFO] Finished at: 2017-10-20T11:13:48+08:00
[INFO] Final Memory: 16M/213M
[INFO] ------------------------------------------------------------------------
guowli@5CG450158J MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven
$ ls -l target/
total 4
drwxr-xr-x 1 guowli 1049089 0 Oct 20 10:56 classes/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 11:13 maven-archiver/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 10:56 maven-status/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 11:01 surefire-reports/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 11:01 test-classes/
-rw-r--r-- 1 guowli 1049089 2151 Oct 20 11:13 testmaven-0.0.1-SNAPSHOT.jar
Maven - 实例-1-手工创建Maven项目的更多相关文章
- Maven - 实例-3-自动创建Maven目录骨架
archetype插件用于创建符合maven规定的目录骨架 方式一:根据提示设置相关参数 guowli@5CG450158J MINGW64 /d/Anliven-Running/Zen/Eclips ...
- 使用Maven在Eclipse中创建Web项目[转]
一.新建 Maven Web项目 1.新建Maven Project new project-->选择 Maven Project --> 下一步 选择工作空间 -->下一步 在Fi ...
- Maven - 在Eclipse中创建Maven项目
本文的前提条件: windows7-64bit jdk1.8.0 Maven-3.5.0 1- 更新Eclipse中Maven配置 1.1- 修改Eclipse根目录下eclipse.ini文件 D: ...
- Maven 梳理 -eclipse中创建Maven的web项目
已验证成功: 1.创建Maven的Web工程 新建Maven工程:File -> New -> Maven Project,具体如下所示: 点击Next进入下述页面,下方的窗口是我们选择所 ...
- 用maven在eclipse中创建Web项目
使用eclipse插件创建一个web project 首先创建一个Maven的Project如下图 我们勾选上Create a simple project (不使用骨架) 这里的Packing 选择 ...
- Maven(二)使用eclipse创建maven多模块项目
maven作为一种自动化构建工具,在现在的企业应用开发中运用非常普遍. 企业项目一般都比较大,多采用maven管理的多模块项目,下面直接上创建步骤 一.创建一个maven项目
- maven环境搭建及创建maven项目
Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. 1.maven下载地址http://maven.apache.org/download.cgi ...
- Idea 创建maven web项目(手工创建)
参考链接:https://www.cnblogs.com/justuntil/p/7511787.html 话不多说,直接上图: 1.创建maven项目 创建项目完成,项目结构如下: 2.项目部署配置 ...
- IntelliJ IDEA 15 创建maven项目
说明 创建Maven项目的方式:手工创建 好处:参考IntelliJ IDEA 14 创建maven项目二(此文章描述了用此方式创建Maven项目的好处)及idea14使用maven创建web工程(此 ...
随机推荐
- C++ 下面的AIDL
转自https://android.googlesource.com/platform/system/tools/aidl/+/brillo-m10-dev/docs/aidl-cpp.md. Bac ...
- Codeforces Round #437 B. Save the problem!
题意: 给你一个方案数,要求你输出满足该条件的总金额,面值数,和各个面值是多少,答案有多个,随便输出一个即可. Examples Input 18 Output 30 41 5 10 25 Input ...
- 20175314 《Java程序设计》第二周学习总结
20175314 <Java程序设计>第二周学习总结 教材学习内容总结 我在APPstore上发现了一个可以支持我们在IOS系统上学习实践Java程序的开发环境,只需要购买专业版就可以使用 ...
- python的序列类
1,我们常见的数据结构有哪些是序列类 序列类型的分类: ① 容器序列:list,tuple,deque(可以防止任意的类型的容器) ② 扁平序列:str,bytes,bytearray,array ...
- js学习(4) 函数
JavaScript有三种声明函数的方法 (1)function命令 function print(s) { console.log(s); } (2)函数表达式 1.var print = func ...
- Add-Migration : 无法将“Add-Migration”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
解决办法: PM>Import-Module C:\Users\Administrator.MACKJON\.nuget\packages\entityframework\6.2.0\tools ...
- Quartz.Net进阶之三:SimpleTrigger详述
以前都是将所有的内容放在一篇文章里,就会导致文章很长,对于学习的人来说,有时候这也是一个障碍.所以,以后我的写作习惯,我就会把我写的文章缩短,但是内容不会少,内容更集中.这样,学习起来也不会很累,很容 ...
- JVM 字节码(四)静态方法、构造代码、this 以及 synchronized 关键字
JVM 字节码(四)静态方法.构造代码.this 以及 synchronized 关键字 一.静态代码 public class ByteCodeStatic { private static fin ...
- W7500P硬件TCP/IP+硬件物理层PHY+Cortex-M0处理器(48MHZ)
W7500P 硬件TCP/IP+硬件物理层PHY+Cortex-M0处理器(48MHZ) 硬件TCP/IP+硬件物理层PHY+Cortex-M0处理器(48MHZ) 如果您发现商品信息不准确,欢迎纠错 ...
- <fieldset>标签
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...