版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/daijiguo/article/details/81989618
一、pom.xml
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<path>/</path>
<port>8080</port>
<uriEncoding>UTF-8</uriEncoding>
<url>http://localhost:8080/manager/text</url>
<server>tomcat7</server>
</configuration>
<executions>
<execution>
<id>executable</id>
<goals>
<goal>exec-war</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
注意事项:
tomcat7-maven-plugin的2.2版本有严重bug,因此,想要正常运行,请使用2.1版本。另,单纯的tomcat7:exec-war
命令是没有任何卵用的,单独运行会报错,只有绑定了package
这个phase,才能正常打包!
就像maven-war-plugin插件的war:war一样,直接运行war:war
命令,打出来的包里面的classe是空的,只有绑定package
这个phase, phase中的maven-compile-plugin插件才会将源码编译并放入classes目录。
二、在开发过程,摆脱外置tomcat服务器
在项目源代码中,通过一条maven命令,启动springmvc项目
mvn tomcat7:run
三、在部署过程,摆脱外置tomcat服务器和maven配置
通过命令
mvn package
得到一个可在外置tomcat服务器部署的war包,和一个可以直接通过java命令运行的jar包,该包命名规则为${artifactId-version-packaging-exec}.jar,对该包执行
java -jar ${artifactId-version-packaging-exec}.jar
即可运行web系统。完全脱离外置服务器和maven搭建。
参考:
https://ufasoli.blogspot.com/2013/11/create-runnable-war-with-embedded.html?q=runnable+war