[英]How to deploy web app on embbeded Tomcat - JavaEE
我想在tomcat embbeded服務器上部署一個web應用程序,我從maven加載:我的休息端點:
@Path("/test")
public class RestTestController {
@GET
public String doNothing(){
return "A";
}
}
和maven設置:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8080</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
執行mvn clean install
之后mvn tomcat7:run
我收到war tomcat啟動的消息,但是當我輸入localhost:8080 / test時我不斷收到404 Not Fount Http響應。 我可能做錯了什么? 我應該在web.xml中添加某種映射嗎?
登錄tomcat顯示我當然部署了我的應用程序:
[INFO] ---------------------< pl.wachkar:take-restaurant >---------------------
[INFO] Building take-restaurant 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ take-restaurant >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ take-restaurant ---
(...)
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ take-restaurant ---
[INFO] Running war on http://localhost:8080/
@EDIT清空web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
</web-app>
你的web.xml是什么樣的? 您至少需要一個歡迎文件列表,以便tomcat知道在啟動時要提供哪個文件
例如:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
我認為你在瀏覽器中輸入了一個錯誤的URL(可能是不完整的)。如果沒有使用web.xml,你應該創建一個擴展Application
類的類,並通過@ApplicationPath("anyString")
注釋它,例如:
import javax.ws.rs.core.Application;
@ApplicationPath("myWebservice")
public class MyConfig extends Application{
}
你不需要實現任何正常工作的方法。這個類可以在任何包中。 並且用於測試正確的URL是:
localhost:port/contextpath/string1/string2
string1是你在Application annotation中指定的(這里是myWebservice)string2是你在資源類的Path annotation中指定的(在你的case測試中)所以我們有
localhost:8080/contextpath/myWebservice/test
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.