在Idea中通过Tomcat运行maven项目

1.在Idea中通过Tomcat的Maven插件运行项目

(1)Tomcat 7的配置(推荐,下载速度较快

在pom.xml中加入下面红色字体部分的配置:

<build>
  <finalName>项目名称</finalName>
  <pluginManagement>

省略…
  </pluginManagement>
  <plugins>
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>2.2</version>
          <configuration>
              <port>8000</port>
              <path>/test</path>
              <uriEncoding>UTF-8</uriEncoding>
              <server>tomcat7</server>
          </configuration>
       </plugin>
   </plugins>
</build>

(2)Tomcat 8的配置(不推荐,非官方仓库,下载速度很慢

在pom.xml中加入下面红色字体部分的配置:

<pluginRepositories>
<pluginRepository>
    <id>alfresco-public</id>
    <url>https://artifacts.alfresco.com/nexus/content/groups/public</url>
</pluginRepository>
<pluginRepository>
    <id>alfresco-public-snapshots</id>
    <url>https://artifacts.alfresco.com/nexus/content/groups/public-snapshots</url>
    <snapshots>
        <enabled>true</enabled>
        <updatePolicy>daily</updatePolicy>
    </snapshots>
</pluginRepository>
<pluginRepository>
    <id>beardedgeeks-releases</id>
    <url>http://beardedgeeks.googlecode.com/svn/repository/releases</url>
</pluginRepository>
</pluginRepositories>

<build>
  <finalName>项目名称</finalName>
  <pluginManagement>

省略…

  </pluginManagement>

  <plugins>

        <plugin>

          <groupId>org.apache.tomcat.maven</groupId>

          <artifactId>tomcat8-maven-plugin</artifactId>

          <version>3.0-r1655215</version>

          <configuration>

              <port>8000</port>

              <path>/test</path>

              <uriEncoding>UTF-8</uriEncoding>

              <server>tomcat7</server>

          </configuration>

       </plugin>

   </plugins>

</build>

(3)检查配置是否成功

在Idea中通过Tomcat运行maven项目

(4)运行项目

出现以下提示信息:

[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ MavenSpringHelloWorld

[INFO] Running war on http://localhost:8000/test

[INFO] Using existing Tomcat server configuration at E:\IdeaWorkSpace\MavenSpringHelloWorld\target\tomcat

[INFO] create webapp with contextPath: /test

 

在浏览器中输入url,即可成功运行。

在Idea中通过Tomcat运行maven项目

2.在Idea中使用外置的Tomcat运行项目

(1)通过Run->Edit Configurations…进入配置界面

在Idea中通过Tomcat运行maven项目

(2)在Tomcat Server中的Local配置Tomcat

在Idea中通过Tomcat运行maven项目

在Idea中通过Tomcat运行maven项目

在Idea中通过Tomcat运行maven项目

然后再点OK,就配好了。