maven配置开发心得

版权声明:本文为博主原创文章,未经博主允许不得转载。讨论交流群:59116211 https://blog.csdn.net/hao474798383/article/details/70259572
Maven使用手册
目录
1.maven常用命令:
2.通用配置步骤
3.其他知识
4.Nexus(ZIP版本)的安装:

1.maven常用命令:
 Mvn compile 编译
 Mvn test 测试
 Mvn clean 清除
 Mvn package 打包
 Mvn install 导入到本地仓库
 Mvn mvn archetype:generate  构建项目,骨架构建好之后,会提示gav信息
2.通用配置步骤
1.首先需要在eclipse中设置如下内容
可以设一个环境变量M2_HOME指向你的maven安装目录
M2_HOME=D:\Apps\apache-maven-3.3.1
然后在Window->Preference->Java->Installed JREs->Edit
在Default VM arguments中设置
-Dmaven.multiModuleProjectDirectory=$M2_HOME
2.  在setting中加入下面内容,保证new的maven项目编译器和运行环境都是1.7的 <profiles> 
<profile>  
  <id>jdk-1.7</id>  
  <activation>  
    <activeByDefault>true</activeByDefault>  
        <jdk>1.7</jdk>  
    </activation>  
    <properties>  
    <maven.compiler.source>1.7</maven.compiler.source>  
    <maven.compiler.target>1.7</maven.compiler.target>  
    <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>  
    </properties>  
   </profile>  
</profiles>


3.修改settings.xml  defulat仓库目录,指向到本地自定义目录中
4.默认仓库下载地址在:lib下 maven-model-builder.jar包中的pom.xml
5.m2eclipse为eclipse插件名称
6.Mvnrepository.com 世界仓库地址
7.如果是download的maven项目,则需要在install之前先把依赖引入,点击maven>enable De........

3.其他知识

需要引入的依赖可以在世界仓库中找到,也可以直接引用本地资源
在Eclipse中使用常用命令,鼠标右键项目中的
POM.XML>>>RUN AS


2.Maven隐藏变量:
${basedir}                     项目根目录
${project.build.directory}     构建目录,缺省为target
${project.build.outputDirectory}     构建过程输出目录,缺省为target/classes
${project.build.finalName}      产出物名称,缺省为${project.artifactId}-${project.version}
${project.packaging}                   打包类型,缺省为jar
${project.xxx}                         当前pom文件的任意节点的内容
3.在GAV中使用本地模块的版本和全局变量名即GA相同
4.依赖范围:Scpoe的属性:
compile为编译加入依赖
provided 打包不加入依赖(tomcat中存在的不需要加入依赖)
runtime 编译不依赖,运行时依赖.(ojdbc5.jar)
test 只有测试时依赖,打包不加入
默认为compile
本身打包不引用.则不传递
A>X1.0>V2.0
B>X2.0
B>V1.0
C > A,B
则C依赖的是X1.0 V1.0
依赖级别相同,哪个先写,就依赖哪个,不相同,取依赖级别高的


****排除依赖包:****
<dependencys>
<dependency>
<exclusions><exclusion>GA</exclusion></exclusions>
<dependency>
<dependencys>
*******************


5.(聚合)导入模块:  <modules><module>需要聚合的模块路径<module></modules>
6.骨架大概包括:
主要聚合模块,松散模块,集成仓库模块(依赖集成仓库),集成仓库模块中使用依赖管理,子类松散模块继承仓库,但无需使用版本号限定依赖.
7.版本管理:0.0.1SNAPSHOT >> 0.0.1RELEASE >> 1.0.1SNAPSHOT>> 0.1.1SNAPSHOT >> 0.0.1RELEASE


4.Nexus(ZIP版本)的安装:
先把BIN添加到PATH中
修改wrapper.conf 中的java环境变量的绝对路径
在CMD中输入nexus 根据相关命令操作nexus,安装成服务
Nexus默认账户:admin/admin123 默认端口8081
Host组(面向内部),提交的数据存到该组中,分snapshot,releases,3rd party
Central 中央工厂下载的文件存放组


1.Maven添加nexus工厂地址(POM)
<repositories>
  	<repository>
  		<id>nexus</id>
  		<name>nexus repository</name>
<url>127.0.0.1:8081/nexus/content/groups/public</url>
  		<releases>
  			<enabled>true</enabled>
  		</releases>
  		<snapshots>
  			<enabled>true</enabled>
  		</snapshots>
</repository>
</repositories>




2.Maven全局添加nexus工厂地址(settings.xml)
<profile>
  <id>nexus</id>
<repositories>
  	  <repository>
  		<id>nexus</id>
  		<name>nexus repository</name>
<url>127.0.0.1:8081/nexus/content/groups/public</url>
  		<releases>
  			<enabled>true</enabled>
  		</releases> 
  		<snapshots>
  			<enabled>true</enabled>
  		</snapshots>
    </repository>
  </repositories>
</profile>


激活:<activeProfile>nexus</activeProfile>
重定向所有工厂路径地址到nexus
<mirror>
   <id>nexusmirror</id>
   <mirrorOf>nexus或者*</mirrorOf>
   <name>Human Readable Name for this Mirror.</name>
   <url>127.0.0.1:8081/nexus/content/groups/public</url>
</mirror>

用重定向需要重写maven   lib包下maven-model-builder包中的pom.xml

复制其中repository到settings中,添加snapshot权限为true

maven的项目,最好先创建一个master项目,此为头项目,无内容,在pom.xml内去集成各个组件用

猜你喜欢

转载自blog.csdn.net/hao474798383/article/details/70259572
今日推荐