I want to deploy a web app on tomcat embbeded server which i load from maven: My rest endpoint:
@Path("/test")
public class RestTestController {
@GET
public String doNothing(){
return "A";
}
}
And maven setup:
<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>
After performing mvn clean install
and later mvn tomcat7:run
I recieve message that war tomcat was started, however when i enter localhost:8080/test i constantly recieve 404 Not Fount Http response. What am I possibly doing wrong? Should I add some kind of mapping into web.xml?
Logs on tomcat shows that I certainly deployed my app:
[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 Empty web.xml file:
<?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>
What does your web.xml look like? You will need at least a welcome file list so that tomcat knows which file to serve at startup
For example:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
i think you entered a wrong url in the brower(maybe incomplete).without using a web.xml you should create a class that extends Application
class and annotate it by @ApplicationPath("anyString")
for example:
import javax.ws.rs.core.Application;
@ApplicationPath("myWebservice")
public class MyConfig extends Application{
}
you don't need to implement any method it works fine.this class can be in any package. and for testing the right url is:
localhost:port/contextpath/string1/string2
string1 is what you specify in Application annotation (here myWebservice) string2 is what you specify in Path annotation on your resource class(in your case test) so we have
localhost:8080/contextpath/myWebservice/test
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.