maven基础的几个指令的作用
- maven clean
- 清空target目录 clean
--- maven-clean-plugin:3.0.0:clean (default-clean) @ testMaven ---
[INFO] Deleting C:\Users\yann\.m2\testMaven\testMaven\target
- maven compile
- resource:copy资源文件
- compile:编译源代码
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ testMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\yann\.m2\testMaven\testMaven\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ testMaven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\yann\.m2\testMaven\testMaven\target\classes
- maven test
- resource:copy资源文件到target
- compile:编译源代码
- testResource:copy test资源文件到target
- testCompile:编译测试代码
- test:执行测试代码
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ testMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ testMaven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\yann\.m2\testMaven\testMaven\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ testMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\yann\.m2\testMaven\testMaven\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ testMaven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\yann\.m2\testMaven\testMaven\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ testMaven ---
- maven package
- resource
- compile
- testResources
- testCompile
- test
- 测试通过后下载项目依赖并且把它们打成一个jar包
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ testMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ testMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ testMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\yann\.m2\testMaven\testMaven\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ testMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ testMaven ---
[INFO]
- maven install
- 在mvn package基础上将jar文件安装到本地的maven仓库
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ testMaven ---
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ testMaven ---
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.pom (0 B at 0 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.15/plexus-utils-3.0.15.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.15/plexus-utils-3.0.15.pom (0 B at 0 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.15/plexus-utils-3.0.15.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.jar (0 B at 0 B/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.15/plexus-utils-3.0.15.jar (0 B at 0 B/s)
[INFO] Installing C:\Users\yann\.m2\testMaven\testMaven\target\testMaven-1.jar to C:\Users\yann\.m2\repository\com\zjpavt\testMaven\1\testMaven-1.jar
[INFO] Installing C:\Users\yann\.m2\testMaven\testMaven\pom.xml to C:\Users\yann\.m2\repository\com\zjpavt\testMaven\1\testMaven-1.pom
[INFO] ------------------------------------------------------------------------
question:
-
- 我本地通过mvn install:install-file -DgroupId=com -DartifactId=client -Dversion=0.1.0 -Dpackaging=jar -Dfile=d:\client-0.1.0.jar
- 当一起共同开发的小伙伴update项目的时候,由于他的maven仓库没有这个本地jar导致编译异常
- 解决方案
- 直接把jar给对方,然后一起install到本地仓库
- 将jar包添加到项目,通过system scope来取
<dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-core</artifactId> <version>1.5</version> <scope>system</scope> <systemPath>${basedir}/WebContent/WEB-INF/lib/hamcrest-core-1.3.jar</systemPath> </dependency>
- 建立maven私服, 在本地仓库和中央仓库都找不到的时候会去该地址查找
/*在 Maven 本地资源库中搜索,如果没有找到,进入下一步,否则退出。 在 Maven 中央存储库搜索,如果没有找到,进入下一步,否则退出。 在java.net Maven的远程存储库搜索,如果没有找到,提示错误信息,否则退出。*/ <repositories> <repository> <id>java.net</id> <url>https://maven.java.net/content/repositories/public/</url> </repository> </repositories>
maven私服的搭建
此次搭建私服主要是为了解决:同事协同工作时,第三方jar包导入maven本地仓库后 其他人的maven依赖报错。
- Nexus Repository Manager OSS 3.x - Windows
- 将压缩包解压到文件夹
- 使用cmd管理员权限 进入目录 C:\Users\yann\Downloads\nexus-3.13.0-01-win64\nexus-3.13.0-01\bin
- 执行指令 nexus.exe/install nexus
- 安装完毕后可以在windows服务中看到nexus服务—启动服务
- 此时访问localhost:8081就可以打开我们的私服管理界面
- 右上角signup 输入用户名密码 admin/admin123
- 顶部导航栏出现齿轮图标 点击进入设置
- 找到右侧导航栏security users 创建新用户
- 输入基本信息后保存退出
- 右侧 repository-repositories-createRepsository-maven2(hosted) 输入name后保存退出
- 此时我们已经可以在设置胖点击 六面体图标 browse中可以看到我们新建的仓库,此时它是空的
- 通过mvn -deploy 可以将我们自己的jar包注册到maven仓库中去
- 此时需要先在我们的pom.xml中设置
- id和url都可以就是我们自己设置的私服仓库的地址
<distributionManagement>
<repository>
<id>zycuseMaven</id>
<url>http://127.0.0.1:8081/repository/zycuseMaven/</url>
</repository>
</distributionManagement>
-
执行mvn deploy 构建成功后我们就可以在仓库管理端看到我们deploy的jar
C:\Users\yann\.m2\testMaven\testMaven>mvn deploy:deploy-file -DgroupId=com.zjpavt -DartifactId=rsa -Dversion=1.0 -Dpackaging=jar -Dfile=C:\oldD\tempPavt\rsaSignCheck\rsa.jar -Durl=http://localhost:8081/repository/zycuseMaven -DrepositoryId=zycuseMaven
-
或者使用网页端直接上传jar
-
通过maven依赖下拉jar文件
- 只需要在maven项目的pom.xml文件中,同级节点中增加
<repositories> <repository> <id>nexus</id> <name>nexus</name> <url>http://127.0.0.1:8081/repository/zycuseMaven/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
- 通过这种方式会优先从我们标记的仓库下载所需要的jar包(local>zycuseMaven>center)
- jiang私服配置添加到setting.xml 暂时 没有是实现
maven 多moudle项目打包
- mvn clean -U package -pl sjxt-service -am
- 在项目的根目录下使用 指定打包service模块 service为项目的一个子模块