*
使用maven插件Tomcat7

<> <>tomcat7-maven-plugin 插件配置

在pom.xml文件加入


*
<>启动Tomcat7

<> <>使用Maven build


*
<>使用Maven 命令

在命令行中输入
mvn clean tomcat7:run
* 1
<> <>其它命令
tomcat7:run -- 启动嵌入式tomcat ,并运行当前项目 tomcat7:deploy --部署一个web war包
tomcat7:reload--重新加载web war包 tomcat7:start --启动tomcat tomcat7:stop --停止tomcat
tomcat7:undeploy--停止一个war包
<> <>启动成功

控制台输出:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
details.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] e3-manager
[INFO] e3-manager-pojo
[INFO] e3-manager-dao
[INFO] e3-manager-interface
[INFO] e3-manager-service
[INFO] e3-manager-web
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building e3-manager 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ e3-manager ---
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager >>>
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager ---
[INFO] Skipping non-war project
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building e3-manager-pojo 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ e3-manager-pojo ---
[INFO] Deleting
C:\Users\Administrator\workspace\e3-manager\e3-manager-pojo\target
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-pojo >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @
e3-manager-pojo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @
e3-manager-pojo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 22 source files to
C:\Users\Administrator\workspace\e3-manager\e3-manager-pojo\target\classes
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-pojo <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-pojo ---
[INFO] Skipping non-war project
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building e3-manager-dao 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ e3-manager-dao ---
[INFO] Deleting
C:\Users\Administrator\workspace\e3-manager\e3-manager-dao\target
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-dao >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @
e3-manager-dao ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 11 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @
e3-manager-dao ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 11 source files to
C:\Users\Administrator\workspace\e3-manager\e3-manager-dao\target\classes
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-dao <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-dao ---
[INFO] Skipping non-war project
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building e3-manager-interface 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @
e3-manager-interface ---
[INFO] Deleting
C:\Users\Administrator\workspace\e3-manager\e3-manager-interface\target
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-interface
>>>
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @
e3-manager-interface ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @
e3-manager-interface ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to
C:\Users\Administrator\workspace\e3-manager\e3-manager-interface\target\classes
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-interface
<<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-interface
---
[INFO] Skipping non-war project
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building e3-manager-service 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ e3-manager-service
---
[INFO] Deleting
C:\Users\Administrator\workspace\e3-manager\e3-manager-service\target
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-service >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @
e3-manager-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @
e3-manager-service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to
C:\Users\Administrator\workspace\e3-manager\e3-manager-service\target\classes
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-service <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-service ---
[INFO] Skipping non-war project
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building e3-manager-web 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ e3-manager-web ---
[INFO] Deleting
C:\Users\Administrator\workspace\e3-manager\e3-manager-web\target
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-web >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @
e3-manager-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 6 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @
e3-manager-web ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to
C:\Users\Administrator\workspace\e3-manager\e3-manager-web\target\classes
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-web <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ e3-manager-web ---
[INFO] Running war on http://localhost:8080/
[INFO] Creating Tomcat server configuration at
C:\Users\Administrator\workspace\e3-manager\e3-manager-web\target\tomcat
[INFO] create webapp with contextPath: 
五月 14, 2018 4:00:51 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8080"]
五月 14, 2018 4:00:51 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Tomcat
五月 14, 2018 4:00:51 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.47
五月 14, 2018 4:00:55 下午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
五月 14, 2018 4:00:55 下午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger
(org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more
info.
五月 14, 2018 4:00:58 下午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring FrameworkServlet 'e3-manager'
五月 14, 2018 4:01:00 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8080"]此时访问http://localhost:8080/ 即可

*
需要修改依赖
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</
artifactId> <version>${servlet-api.version}</version><!-- 版本自己定义 --> <scope>
provided</scope><!-- 必须要有 --> </dependency>
<> <>启动成功但是404

遇到404 肯定是因为路径错误 
仔细检查你的默认html或者jsp等等是否与web.xml中配置的一致
<welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file
>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>
default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-
file>default.jsp</welcome-file> </welcome-file-list>
博客制作时参考博客为:https://blog.csdn.net/m0_37995707/article/details/77899345
欢迎访问,互相学习,感谢。

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信