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

来源:互联网 发布:淘宝领取的优酷会员 编辑:程序博客网 时间:2024/05/29 09:51

  • 使用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    --启动tomcattomcat7:stop    --停止tomcattomcat7: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-file>    <welcome-file>default.jsp</welcome-file></welcome-file-list>
原创粉丝点击