若想在 Maven 中使用 Tomcat 服務器,需要在 pom.xml 文件中的 <build></build> 標簽中添加以下代碼
<!-- Maven項目編譯插件 --> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <!-- 不指定時默認采用最新插件版本 --> <configuration> <!-- 根據實際情況設置 JDK --> <source>1.7</source> <!-- 源代碼使用的開發版本 --> <target>1.7</target> <!-- 需要生成的目標class文件的編譯版本 --> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- Tomcat 插件配置 --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <!-- 使用內置的模擬Tomcat服務器 --> <path>/SpringMVC_170422_RESTful_CRUD</path> <uriEncoding>UTF-8</uriEncoding> <port>9527</port> <mode>context</mode> <contextReloadable>true</contextReloadable> </configuration> </plugin> </plugins>