结合使用嵌入式Tomcat和Maven tomcat插件
生活随笔
收集整理的這篇文章主要介紹了
结合使用嵌入式Tomcat和Maven tomcat插件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用Eclipse WTP開發Java Web應用程序時,我們需要在計算機中安裝tomcat才能執行該應用程序。
如果在項目上使用Maven,則可以使用tomcat插件運行嵌入式tomcat安裝并測試應用程序。 如下所示,這非常簡單。
OBS:要執行本文中給出的步驟,您需要在Eclipse中安裝m2e插件。
使用此原型創建Web項目時,它已經添加了index.jsp文件。
現在,我們需要在pom.xml中添加插件信息,如下所示。 在這個例子中,我們使用了tomcat 7.x的插件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>br.com.xicojunior</groupId><artifactId>test</artifactId><packaging>war</packaging><version>0.0.1-SNAPSHOT</version><name>teste Maven Webapp</name><url>http://maven.apache.org</url><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies><build><finalName>test</finalName><plugins><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>2.2</version></plugin></plugins></build> </project>我們在文件中所做的唯一更改是添加了部分以添加tomcat 7插件。
添加插件信息后,我們可以使用以下Maven目標對其進行測試:
clean install tomcat7:run要在日食中執行這些目標:
期望在控制臺中看到以下內容:
[INFO] Running war on http://localhost:8080/test [INFO] Creating Tomcat server configuration at C:\workspace\pessoal\redis\teste\target\tomcat [INFO] create webapp with contextPath: /test 18/01/2014 17:43:53 org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["http-bio-8080"] 18/01/2014 17:43:53 org.apache.catalina.core.StandardService startInternal INFO: Starting service Tomcat 18/01/2014 17:43:53 org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet Engine: Apache Tomcat/7.0.47 18/01/2014 17:43:54 org.apache.tomcat.websocket.server.WsSci onStartup INFO: JSR 356 WebSocket (Java WebSocket 1.0) support is not available when running on Java 6. To suppress this message, run Tomcat on Java 7, remove the WebSocket JARs from $CATALINA_HOME/lib or add the WebSocketJARs to the tomcat.util.scan.DefaultJarScanner.jarsToSkip property in $CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7 WebSocket API will be available. 18/01/2014 17:43:54 org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-bio-8080"]然后我們只需要在瀏覽器中測試給定的URL,就我而言: http:// localhost:8080 / test
- 您可以在插件頁面中找到更多信息和選項。
翻譯自: https://www.javacodegeeks.com/2014/01/using-an-embedded-tomcat-with-maven-tomcat-plugin.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的结合使用嵌入式Tomcat和Maven tomcat插件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华理健康安卓(健康 安卓)
- 下一篇: 网络配置linux(网络配置 linux