您的位置:首页 > 运维架构 > Tomcat

使用maven插件Tomcat7 启动成功但是404的问题

2017-09-08 21:41 1696 查看
使用maven插件Tomcat7
tomcat7-maven-plugin 插件配置

启动Tomcat7
使用Maven build

使用Maven 命令

其它命令

启动成功

启动失败问题

启动成功但是404

使用maven插件Tomcat7

tomcat7-maven-plugin 插件配置

在pom.xml文件加入

<build>
<!-- 配置插件 -->
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<update>true</update> <!-- 热部署 -->
<charset>utf-8</charset> <!-- 设置字符集 -->
<uriEncoding>UTF-8</uriEncoding><!-- 设置uri编码 -->
<port>8888</port> <!-- 设置端口 -->
<path>/</path><!-- 设置默认访问应用的路径 -->
<url>http://127.0.0.1:8888/manager/text</url>
</configuration>
</plugin>
</plugins>
</build>


启动Tomcat7

使用Maven build



使用Maven 命令

在命令行中输入

mvn clean tomcat7:run


其它命令

tomcat7:run -- 启动嵌入式tomcat ,并运行当前项目
tomcat7:deploy   --部署一个web war包
tomcat7:reload   --重新加载web war包
tomcat7:start    --启动tomcat
tomcat7:stop    --停止tomcat
tomcat7:undeploy--停止一个war包


启动成功

控制台输出:

[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ taotao-manager-web ---
[INFO] Running war on http://localhost:8888/ [INFO] Creating Tomcat server configuration at D:\JetBrains\IdeaProjects\taotao\taotao-manager\taotao-manager-web\target\tomcat
[INFO] create webapp with contextPath:
九月 08, 2017 8:38:08 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8888"]
九月 08, 2017 8:38:08 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Tomcat
九月 08, 2017 8:38:08 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.47
九月 08, 2017 8:38:12 下午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
九月 08, 2017 8:38:12 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8888"]


此时访问
http://localhost:8888/
即可

启动失败问题

需要修改依赖

<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-
a296
file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  tomcat 插件 maven