maven项目的构建与启动

一、新建一个maven项目,如图


1、选择maven project,点击next


maven项目的构建与启动


2、默认选项,不用修改,点击next


maven项目的构建与启动


3、默认选项,不用修改,点击next


maven项目的构建与启动


4、输入Group Id和 Artifact Id,Artifact Id的值为项目名,一般首字母大写,点击finish


maven项目的构建与启动


5、完成,建成项目结构为下图


maven项目的构建与启动


二,按照上面步骤新建Maven项目Test,在第三步的时候选择


maven项目的构建与启动


第四步的时候


maven项目的构建与启动


点击finish


maven项目的构建与启动


三、把Test项目的webapp目录copy到TestMaven项目的/src/main目录下,完成后可删除Test项目


maven项目的构建与启动


四、选中webapp目录,右键点击,把此目录修改为源目录


maven项目的构建与启动


修改成功


maven项目的构建与启动


五、双击打开项目的pom.xml文件,修改项目打包格式为war


maven项目的构建与启动


六、pom.xml文件中添加启动相关xml代码


<build>
    <finalName>web</finalName>
    <plugins>
        <plugin> 
            <groupId>org.apache.tomcat.maven</groupId> 
            <artifactId>tomcat7-maven-plugin</artifactId> 
            <version>2.2</version> 
            <configuration> 
            <uriEncoding>UTF-8</uriEncoding>
            <port>8088</port>
            <path>/TestMaven</path> <!-- 应用的部署位置 -->
            </configuration> 
        </plugin>
    </plugins>
  </build>

maven项目的构建与启动


七、选中项目右键点击maven build


maven项目的构建与启动


在Goals后面的输入框中填写tomcat7:run


maven项目的构建与启动


八、点击Apply和run,启动成功


maven项目的构建与启动

网址输入http://localhost:8088/TestMaven/

maven项目的构建与启动