使用maven外掛Tomcat7 啟動成功但是404的問題
阿新 • • 發佈:2018-12-31
使用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>