使用maven插件Tomcat7 啓動成功但是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-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章