一、本地电脑环境安装maven插件,配置环境变量
1、从apache网上下载maven项目的压缩包。下载地址为:http://maven.apache.org/download.html。比如现在最新的Maven版本是3.5.4,那么我下载好的安装文件就是apache-maven-3.5.4.zip。
2、将下载后的压缩包解压到Maven的安装目录,比如说是D:\\develop,那么解压后就是D:\\develop\\apache-maven-3.5.4。
3、添加环境变量MVN_HOME,其值为Maven的家目录,如D:\\develop\\apache-maven-3.5.4。
4、将环境变量MVN_HOME加入到PATH变量中,对于windows系统,可以在PATH变量的值后面加上“;%MVN_HOME%\bin”
经过以上几步之后Maven就安装成功了。接下来我们可以在命令窗口使用mvn --version来验证一下Maven是否安装成功。如能正确输出Maven的安装版本,则表示它安装成功了。
二、Maven配置文件settings.xml相关配置
配置server
<server> <id>nexus-release</id> <username>admin</username> <password>***</password> </server> <server> <id>nexus-snapshot</id> <username>admin</username> <password>***</password> </server> <server> <id>nexus</id> <username>admin</username> <password>***</password> </server>
配置mirror
<mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <name>trasenNexus</name> <url>http://***/nexus/content/groups/public/</url> </mirror>
详细配置可参考:Maven配置文件settings.xml详解
三、eclipse配置maven插件
1、windows--preferences--Maven--User Settings
2、设置User Settings文件为本地Maven安装路径下的conf/settings.xml
三、项目转换Maven
1、打开eclipse,在项目上面右键--configure--Convert to Maven Project
2、修改pom.xml文件
1)加properties配置
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties>
2)增加scm配置
<scm> <connection>scm:svn:https://***/svn/Master/Products/WISEHIS/NURSE/trunk/nurse</connection> <developerConnection>scm:svn:https://***/svn/Master/Products/WISEHIS/NURSE/trunk/nurse</developerConnection> <url>tags/nurse</url> </scm>
3)增加dependencies依赖
<dependencies> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency> ...... </dependencies>
4)增加distributionManagement配置
<!-- 使用分发管理将本项目打成jar包,直接上传到指定服务器 --> <distributionManagement> <!--正式版本--> <repository> <!-- nexus服务器中用户名:在settings.xml中<server>的id--> <id>nexus-release</id> <!-- 这个名称自己定义 --> <name>Nexus Release Repository</name> <url>http://***/nexus/content/repositories/releases/</url> </repository> <!--快照 --> <snapshotRepository> <id>nexus-snapshot</id> <name>Nexus Snapshot Repository</name> <url>http://***/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
5)增加repositories配置
<!--仓库路径 --> <repositories> <repository> <id>nexus</id> <name>Public Repository of trasenNexus</name> <url>http://***/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
6)增加build配置
<build> <finalName>${project.artifactId}-${project.version}</finalName> <sourceDirectory>src</sourceDirectory> <resources> <resource> <directory>src</directory> <includes> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>resource</directory> <includes> <include>**/**</include> </includes> </resource> </resources> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <warSourceDirectory>WebRoot</warSourceDirectory> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.8</version> <executions> <execution> <id>attach-javadocs</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> <configuration> <additionalparam>-Xdoclint:none</additionalparam> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> </plugin> </plugins> </build>
4、设置部署目录
右键--build path--Configuer Build Path
设置Web Deployment Assembly
点击ADD
将Maven包加入部署目录
四、发布Maven正式版本
1、将未提交SVN的文件全部提交
执行命令:mvn release:prepare
我们多了一个tag:https://192.168.1.100:8443/svn/myapp/tags/myapp-1.0/,这就是需要发布的版本1.0。
再看看trunk中的POM,其版本自动升级成了1.1-SNAPSHOT。
mvn release:perform
还没有评论,来说两句吧...