本地仓库的设置 #
远程仓库–>本地仓库
maven仓库
- 存放maven工具自己的jar包
- 第三方jar,比如mysql驱动
- 自己写的程序,可以打包为jar,存放到仓库
分类
本地仓库(本机):位于自己计算机中,磁盘中某个目录
默认位置 登录操作系统的账号目录/.m2/repository C:\Users\ly.m2\repository
可修改 比如放在d盘中
英[rɪˈpɒzətri] D:\software\apache-maven-3.8.6\repository 备份并编辑
改成左斜杠的方式
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd"> <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <localRepository>D:/software/apache-maven-3.8.6/repository</localRepository>
把之前user下的repository的文件都拷贝到 D:/software/apache-maven-3.8.6/repository 下 然后再对Hello项目进行编译
mvn compile
发现不会下载任何文件,且user下的repository也不会再进行下载下面的资源是从maven中下载,或者用maven打包的
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.bjpowernode</groupId> <artifactId>ch01-maven</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <properties> <java.version>1.8</java.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.9</version> </dependency> </dependencies> </project>
- mvn命令需要在pom.xml所在的目录下执行
仓库的工作方式 #
生命周期插件命令 #
- 包括 清理(删除target文件,但是不处理已经install的jar)、编译(当前目录生成target目录,放置编译主程序之后生成的字节码)、测试(生成surefire-reports,保存测试结果)、报告、打包(打包主程序[编译、编译测试、测试,并按照pom.xml配置把主程序打包成jar包或war包])、安装(把本工程打包,并按照工程坐标保存到本地仓库中)、部署(打包,保存到本地仓库,并保存到私服中,且自动把项目部署到web容器中)
- 插件:要完成构建项目的各个阶段,要使用maven的命令,执行命令的功能,是通过插件完成的 插件就是jar,一些类
- 命令:执行maven功能,通过命令发出,比如mvn compile(编译时由相关的类来操作)
junit使用 #
单元测试 junit:单元测试的工具,java中经常使用 单元,java中指的是方法,方法就是一个单元,方法是测试的最小单位
作用,使用junit去测试方法是否完成了要求,开发人员自测
使用单元测试
加入junit的依赖(需要用他的类和方法)
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12> <scope>test</scope> </dependency>
在src/test/java目录中创建测试类文件,写测试代码
- 测试类的定义,名称一般是Test+要测试的类名称
- 测试它的包名和要测试的类包名一样
- 在类中定义方法,要测试的代码
- 方法定义:public方法,没有返回值,名称自定义(建议Test+测试的方法名称) 方法没有参数
- 测试类中的方法,可以单独执行,测试类也可以单独执行
- 在该方法上面加入注解
@Test
注意:mvn compile的时候,会下载3.8.2的jar包
创建测试类和测试方法 #
package com.bjpowernode;
//导入包
import org.junit.Assert;
import org.junit.Test;
public class TestHelloMaven{
//定义多个独立的测试方法,每个方法都是独立的
public void testAddNumber(){
System.out.println("执行了测试方法testAddNumber");
HelloMaven hello=new HelloMaven();
int res=hello.addNumber(10,20);
//把计算结果res交给junit判断
//期望值,实际值
Assert.assertEquals(30,res);
}
}
相关命令 #
mvn clean ,清理,删除以前生成的数据(删除target目录)
插件及版本 maven-clean-plugin:2.5
d:\Users\ly\Documents\git\mavenwork\Hello>mvn clean [INFO] Scanning for projects... [INFO] [INFO] ---------------------< com.bjpowernode:ch01-maven >--------------------- [INFO] Building ch01-maven 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ ch01-maven --- [INFO] Deleting d:\Users\ly\Documents\git\mavenwork\Hello\target [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.354 s [INFO] Finished at: 2022-07-09T17:03:46+08:00 [INFO] ------------------------------------------------------------------------
代码的编译 mvn compile:编译命令,把src/main/java 目录中的java代码编译为class文件 同时把class文件拷贝到target/classes目录,这个目录classes是存放类文件的根目录(也叫做类路径,classpath)
编译后放到target\classes中 插件:maven-compiler-plugin:3.1 编译代码 maven-resources-plugin:2.6:resources 资源插件,作用是把src/main/resources目录中的文件拷贝到target/classes 目录中
λ mvn compile [INFO] Scanning for projects... [INFO] [INFO] ---------------------< com.bjpowernode:ch01-maven >--------------------- [INFO] Building ch01-maven 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ch01-maven --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent![INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ch01-maven --- [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:\Users\ly\Documents\git\mavenwork\Hello\target\classes [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.164 s [INFO] Finished at: 2022-07-09T17:20:30+08:00 [INFO] ------------------------------------------------------------------------
测试resources插件
mvn test-compile:编译命令,编译src/test/java 目录中的源文件,把生成的class拷贝到target/test-classes目录中,同时把src/test/resources目录中的文件拷贝到test-classes目录 命令执行前
执行后
插件 maven-resources-plugin:2.6:resources maven-compiler-plugin:3.1:compile maven-resources-plugin:2.6:testResources maven-compiler-plugin:3.1:testCompile
λ mvn test-compile [INFO] Scanning for projects... [INFO] [INFO] ---------------------< com.bjpowernode:ch01-maven >--------------------- [INFO] Building ch01-maven 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- Downloading from central: https://repo.maven.apache.org/maven2/junit/junit/4.12/junit-4.12.jar Downloading from central: https://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar (45 kB at 24 kB/s) Downloaded from central: https://repo.maven.apache.org/maven2/junit/junit/4.12/junit-4.12.jar (315 kB at 118 kB/s) [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ch01-maven --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent![INFO] Copying 2 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ch01-maven --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ch01-maven --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent![INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ ch01-maven --- [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:\Users\ly\Documents\git\mavenwork\Hello\target\test-classes [WARNING] /D:/Users/ly/Documents/git/mavenwork/Hello/src/test/java/com/bjpowernode/TestHelloMaven.java:[2,7] 编码GBK的不可映射字符 [WARNING] /D:/Users/ly/Documents/git/mavenwork/Hello/src/test/java/com/bjpowernode/TestHelloMaven.java:[8,42] 编码GBK的不可映射字符 [WARNING] /D:/Users/ly/Documents/git/mavenwork/Hello/src/test/java/com/bjpowernode/TestHelloMaven.java:[14,29] 编码GBK的不可映射字符 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 8.085 s [INFO] Finished at: 2022-07-09T17:28:14+08:00 [INFO] ------------------------------------------------------------------------
mvn test 测试命令,执行test-classes目录的程序,测试src/main/java目录中的主程序是否符合要求 注意,这里还是会用到编译插件和资源插件,从 T E S T S 开始测试 结果Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 测试插件 maven-surefire-plugin:2.12.4
λ mvn test [INFO] Scanning for projects... [INFO] [INFO] ---------------------< com.bjpowernode:ch01-maven >--------------------- [INFO] Building ch01-maven 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ch01-maven --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent![INFO] Copying 2 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ch01-maven --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ch01-maven --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent![INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ ch01-maven --- [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:\Users\ly\Documents\git\mavenwork\Hello\target\test-classes [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ ch01-maven --- [INFO] Surefire report directory: D:\Users\ly\Documents\git\mavenwork\Hello\target\surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.bjpowernode.TestHelloMaven 执行了测试方法testAddNumber hello maven -addNumber Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.131 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.630 s [INFO] Finished at: 2022-07-09T17:32:49+08:00 [INFO] ------------------------------------------------------------------------
测试报告
测试失败的情况
结果
λ mvn test [INFO] Scanning for projects... [INFO] [INFO] ---------------------< com.bjpowernode:ch01-maven >--------------------- [INFO] Building ch01-maven 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ch01-maven --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent![INFO] Copying 2 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ch01-maven --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ch01-maven --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent![INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ ch01-maven --- [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:\Users\ly\Documents\git\mavenwork\Hello\target\test-classes [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ ch01-maven --- [INFO] Surefire report directory: D:\Users\ly\Documents\git\mavenwork\Hello\target\surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.bjpowernode.TestHelloMaven 执行了测试方法testAddNumber hello maven -addNumber Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.217 sec <<< FAILURE! testAddNumber(com.bjpowernode.TestHelloMaven) Time elapsed: 0.043 sec <<< FAILURE! java.lang.AssertionError: expected:<60> but was:<30> at org.junit.Assert.fail(Assert.java:88) at org.junit.Assert.failNotEquals(Assert.java:834) at org.junit.Assert.assertEquals(Assert.java:645) at org.junit.Assert.assertEquals(Assert.java:631) at com.bjpowernode.TestHelloMaven.testAddNumber(TestHelloMaven.java:15) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Results : Failed tests: testAddNumber(com.bjpowernode.TestHelloMaven): expected:<60> but was:<30> Tests run: 1, Failures: 1, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 8.018 s [INFO] Finished at: 2022-07-09T17:35:38+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project ch01-maven: There are test failures. [ERROR] [ERROR] Please refer to D:\Users\ly\Documents\git\mavenwork\Hello\target\surefire-reports for the individual test results. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
mvn package 打包,作用是把项目中的资源class文件和配置文件,都放到一个压缩包中,默认压缩文件是jar类型,web应用是war类型,扩展名jar/war 这里进行了编译、测试、打包 [INFO] Building jar: D:\Users\ly\Documents\git\mavenwork\Hello\target\ch01-maven-1.0-SNAPSHOT.jar 打包插件 maven-jar-plugin:2.4:jar (default-jar) @ ch01-maven maven-jar-plugin:2.4用来执行打包,会生成jar扩展名文件
λ mvn package [INFO] Scanning for projects... [INFO] [INFO] ---------------------< com.bjpowernode:ch01-maven >--------------------- [INFO] Building ch01-maven 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ch01-maven --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 2 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ch01-maven --- [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:\Users\ly\Documents\git\mavenwork\Hello\target\classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ch01-maven --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ ch01-maven --- [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:\Users\ly\Documents\git\mavenwork\Hello\target\test-classes [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ ch01-maven --- [INFO] Surefire report directory: D:\Users\ly\Documents\git\mavenwork\Hello\target\surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.bjpowernode.TestHelloMaven 执行了测试方法testAddNumber hello maven -addNumber Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.135 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ ch01-maven --- [INFO] Building jar: D:\Users\ly\Documents\git\mavenwork\Hello\target\ch01-maven-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.624 s [INFO] Finished at: 2022-07-09T17:40:44+08:00 [INFO] ------------------------------------------------------------------------
生成ch01-maven-1.0-SNAPSHOT.jar 坐标
<groupId>com.bjpowernode</groupId> <artifactId>ch01-maven</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging>
打包的文件名 artifactId-version.packaging 查看jar
打包的文件中,包括src/main目录中所有的生成的class文件和配置文件(resources下),和测试test无关
mvn install 把生成的打包文件(jar)安装到maven仓库中 插件:maven-install-plugin-2.4
λ mvn install [INFO] Scanning for projects... [INFO] [INFO] ---------------------< com.bjpowernode:ch01-maven >--------------------- [INFO] Building ch01-maven 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ch01-maven --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 2 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ch01-maven --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ch01-maven --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ ch01-maven --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ ch01-maven --- [INFO] Surefire report directory: D:\Users\ly\Documents\git\mavenwork\Hello\target\surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.bjpowernode.TestHelloMaven 执行了测试方法testAddNumber hello maven -addNumber Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.162 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ ch01-maven --- [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ ch01-maven --- [INFO] Installing D:\Users\ly\Documents\git\mavenwork\Hello\target\ch01-maven-1.0-SNAPSHOT.jar to D:\software\apache-maven-3.8.6\repository\com\bjpowernode\ch01-maven\1.0-SNAPSHOT\ch01-maven-1.0-SNAPSHOT.jar [INFO] Installing D:\Users\ly\Documents\git\mavenwork\Hello\pom.xml to D:\software\apache-maven-3.8.6\repository\com\bjpowernode\ch01-maven\1.0-SNAPSHOT\ch01-maven-1.0-SNAPSHOT.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.063 s [INFO] Finished at: 2022-07-09T17:48:43+08:00 [INFO] ------------------------------------------------------------------------
如上,
Installing D:\Users\ly\Documents\git\mavenwork\Hello\target\ch01-maven-1.0-SNAPSHOT.jar to D:\software\apache-maven-3.8.6\repository\com\bjpowernode\ch01-maven\1.0-SNAPSHOT\ch01-maven-1.0-SNAPSHOT.jar
路径 com\bjpowernode\ch01-maven\1.0-SNAPSHOT ,如下,跟坐标有关
<groupId>com.bjpowernode</groupId> <artifactId>ch01-maven</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <!--groupId出现点,则使用\(文件夹)分割 artifactId 独立文件夹 version 独立文件夹 -->
结果
部署 mvn deploy 部署主程序(把本工程打包,按照本工程的坐标保存到本地仓库中,并且保存到私服仓库中,还会自动把项目部署到web容器中
以上命令是可以组合着用的
λ mvn clean compile [INFO] Scanning for projects... [INFO] [INFO] ---------------------< com.bjpowernode:ch01-maven >--------------------- [INFO] Building ch01-maven 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ ch01-maven --- [INFO] Deleting D:\Users\ly\Documents\git\mavenwork\Hello\target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ch01-maven --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 2 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ch01-maven --- [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:\Users\ly\Documents\git\mavenwork\Hello\target\classes [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.725 s [INFO] Finished at: 2022-07-09T17:53:36+08:00 [INFO] ------------------------------------------------------------------------
配置插件 #
常用插件设置
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build>
- 先看一下,目前的版本 maven-compiler-plugin:3.1:compile