maven基础配置及使用
一、MyEclipse添加Maven插件的方法和步骤
Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。
1. 下载maven
2. 下载完之后直接解压到电脑的目录,这里注意,目录的路径中最好不要带有空格
3. 接下来进行maven环境的搭建
a) 新建环境变量M2_HOME 指向maven 安装目录
b) 在path尾部添加%M2_HOME%\bin
c) 检查是否安装成功
d) 打开cmd输入mvn –v 如果输出maven代表安装成功
4. 打开maven安装目录下conf文件中找到settings文件进行配置
a) 配置maven仓库的位置(自定义,没硬性要求)
b) 配置私服地址
5. 配置MyEclipse的maven插件
a) 添加自己安装的maven文件
6. a) 配置maven的jdk统一使用jdk1.7
7. a) maven的自定义配置(配置完成后,点击updatesettings按钮,之后点击apply按钮)
二、Myeclipse中用tomcat部署maven项目
三、maven主要配置及命令使用
1.依赖远程库
需要配置maven的setings文件,并修改pom文件
<properties>
<project.build.sourceEncoding>GBK</project.build.sourceEncoding>
<springframework.version>2.5.6</springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework </groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.version}</version>
</dependency>
</dependencies>
2.安装包到本地库
mvn install:install-file -DgroupId=quartz-DartifactId=quartz -Dversion=1.5.0 -Dpackaging=jar -Dfile=quartz-1.5.0.jar
3.本地jar包引用
<dependency>
<groupId>tpme.LeadingEX.AE</groupId>
<artifactId>aeproxyrmi</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/aeproxyrmi.jar</systemPath>
</dependency>
4.踢出不必要的jar包exclusions
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.6</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
</exclusions>
</dependency>
5.上传第三方包到私库
5.1 使用mvn命令
mvn deploy:deploy-
file
-DgroupId=org.apache.thrift -DartifactId=libthrift -Dversion=1.12 -Dpackaging=jar -Dfile=D:\thrift-0.9.2.jar -Durl=http:
//ip
:port
/nexus/content/repositories/thirdparty/
-DrepositoryId=thirdparty
5.2 使用浏览器管理页面
详见 https://blog.****.net/lzy_lizhiyang/article/details/45056703
四、maven项目pom继承
父pom:
子pom:
Myeclipse2016 maven项目问题:
The org.eclipse.m2e:lifecycle-mapping plugin doesn't exist actually. It should be usedfrom the <build><pluginManagement> section of your pom.xml. That way, it'snot resolved by Maven but can be read by m2e.
But a more practical solution to yourproblem would be to install the m2e build-helperconnector in eclipse. You can install it from the Window > Preferences > Maven > Discovery > Open Catalog. That way build-helper-maven-plugin:add-sources would be called in eclipse withouthaving you to change your pom.xml.