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

一、pom.xml

            
                org.apache.tomcat.maven
                tomcat7-maven-plugin
                2.1
                
                    /
                    8080
                    UTF-8
                    http://localhost:8080/manager/text
                    tomcat7
                
                
                    
                        executable
                        
                            exec-war
                        
                        package
                    
                
            

注意事项:
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

你可能感兴趣的:(Maven)