在Eclipse中配置Maven
指定配置安裝maven的路徑
Eclipse自帶的Mavan本地倉庫:
改成我們前面所配置的倉庫和setting,你也可以直接使用默認自帶的
關聯setting.xml文件
配置setting.xml,加上阿里代理鏡像
中央倉庫的地址在國外直接下載jar會很慢,所以我們需要通過代理的方式下載
<!-- 阿里代理鏡像地址 -->
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
加入Tomcat插件
將動態web項目達成war包手動添加到tomcat的wabapp這種方式很麻煩,在開發過程中不高效,這時我們可以在項目中集成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>com.dpb</groupId>
<artifactId>MavenDemo01</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- 因為是web項目所以需要servlet -->
<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!-- 端口號 -->
<port>8082</port>
<!-- /表示訪問路徑 省略項目名 -->
<path>/</path>
<!-- 設置編碼方式 -->
<uriEncoding>utf-8</uriEncoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
運行:
輸入: tomcat7:run 然后運行
第一次要下載一些資源會比較慢。