This might be a pretty simple question, may be it's a duplicate (though I did not find any till now), but somehow I'm stuck and need to resolve it as soon as possible.
Basically, I am trying to make a simple RESTful web service using JAX-RS API. Somehow, I am unable to so. This is my first encounter with web services and I am pretty sure I am doing a silly mistake though after lot of googling I have failed to resolve it.
So, here is my project structure -
MessageResource.java
package com.rest.jersey.messenger.resource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/messages")
public class MessageResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getMessage() {
return "Hello World";
}
}
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"
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">
<display-name>messenger</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey_REST_Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.rest.jersey.messenger.resource</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey_REST_Service</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
URL I am hitting is : http://localhost:8090/messenger/webapi/messages
Result: I am getting error page -
HTTP Status 404 - /messenger/webapi/messages
type Status report
message /messenger/webapi/messages
description The requested resource is not available.
Note: I'm not using maven. I want to set-up the project manually. And, I am using port 8090 instead of 8080.
[Edit]
I am getting below warning while starting Tomcat server:
WARNING: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Messenger' did not find a matching property.
I have tried below solution. Still same error.
Double click on your tomcat server.
It will open the server configuration.
Under server options check ‘Publish module contents to separate XML files’ checkbox