上述環境配置可參照我以前編寫的maven搭建方面的文檔。本文着重介紹myeclipse2014下maven項目的搭建及部署java
進入myeclipse2014,在菜單欄選擇windows-preferences-Maven4myeclipse,以下圖設置web
其中Installations中選擇maven的安裝路徑,個人路徑是C:\java\maven3.2.1.apache
User setting中選擇的是C:\java\maven3.2.1\conf\Setting.xmlwindows
Setting.xml增長本地lib庫的目錄api
<localRepository>F:/myproject/maven/repo</localRepository>tomcat
同時增長tomcat服務的配置app
<servers> eclipse
<id>yibabe</id> webapp
<username>admin</username> jsp
<password>1111111</password>
</servers>
如圖:
進入myeclipse2014,點擊菜單File-New-Web project,如圖
<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>
添加j2EE包
1)右鍵選擇項目 Run as -> Maven install 進行安裝,並將項目打成war包
2)右鍵選擇項目 Run as -> Maven Run運行項目
3)打開首頁http://localhost:8082/yibabe2
至此,項目部署成功。