利用tomcat7-maven-plugin插件,do what you want to do!

一、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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值