一、环境
1.1 myeclipse2014
1.2 maven3.2.1
1.3 jdk1.7
上述环境配置可参照我之前编写的maven搭建方面的文档。本文着重介绍myeclipse2014下maven项目的搭建及部署
二、myeclipse2014环境中maven的配置
进入myeclipse2014,在菜单栏选择windows-preferences-Maven4myeclipse,如下图设置
其中Installations中选择maven的安装路径,我的路径是C:\java\maven3.2.1.
User setting中选择的是C:\java\maven3.2.1\conf\Setting.xml
Setting.xml增加本地lib库的目录
<localRepository>F:/myproject/maven/repo</localRepository>
同时增加tomcat服务的配置
<servers>
<id>yibabe</id>
<username>admin</username>
<password>1111111</password>
</servers>
如图:
三、Maven项目搭建
进入myeclipse2014,点击菜单File-New-Web project,如图
四、Pom.xml及tomcat插件启动配置
4.1、Pom.xml及tomcat插件配置如下
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>yibabe2</groupId>
<artifactId>yibabe2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>yibabe2</name>
<description/>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>1.2.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<version>3.1</version>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<server>yibabe2</server>
<port>8082</port>
<url>http://localhost:8082/</url><!--端口号-->
<path>/yibabe2</path>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
4.2 项目Java bulid path配置
添加j2EE包
4.3 Maven命令配置
五 项目运行
1)右键选择项目 Run as -> Maven install 进行安装,并将项目打成war包
2)右键选择项目 Run as -> Maven Run运行项目
3)打开首页http://localhost:8082/yibabe2
至此,项目部署成功。
来源:oschina
链接:https://my.oschina.net/u/1032948/blog/219633