2

I am trying to create a simple web service by referring this site : http://www.connect2java.com/webservices/jax-rs-applicationpath-annotationno-web-xml-example-in-jersey/

I am using

NetBeans IDE 8.0.2

Java 8.0 JDK 1.7

JBoss Server

Here is my code :

RestfulApplicationPathAnnotationExample.java:

package com.connect2java.RestfulApplicationPathAnnotationExample;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/hello")
public class RestfulApplicationPathAnnotationExample {
    @GET
    @Produces(MediaType.TEXT_HTML)     
     public Response sayHello() {

        String str ="<H1>Hi!!! welcome to @ApplicationPath Annotation Example in Restful webservices  </H1> ";

        return Response.status(200).entity(str).build();

    }

}

MyApplication.java:

package com.connect2java.RestfulApplicationPathAnnotationExample;

import javax.ws.rs.ApplicationPath;

import org.glassfish.jersey.server.ResourceConfig;

    @ApplicationPath("resources")
    public class MyApplication extends ResourceConfig {
        public MyApplication() {
            packages("com.connect2java.RestfulApplicationPathAnnotationExample");
        }

    }

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

run output:

run output

error displayed at server:

13:06:39,832 INFO  [TomcatDeployer] undeploy, ctxPath=/RestfulApplicationPathAnnotationExample, warUrl=.../tmp/deploy/tmp7253522143789622225RestfulApplicationPathAnnotationExample-exp.war/
13:06:40,253 INFO  [TomcatDeployer] deploy, ctxPath=/RestfulApplicationPathAnnotationExample, warUrl=.../tmp/deploy/tmp3990284126749515271RestfulApplicationPathAnnotationExample-exp.war/
13:06:40,316 INFO  [WebappClassLoader] validateJarFile(C:\jboss\server\default\.\tmp\deploy\tmp3990284126749515271RestfulApplicationPathAnnotationExample-exp.war\WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

Program structure:

enter image description here

I get "Hello World" output in the webpage at this URL:

http://localhost:8080/RestfulApplicationPathAnnotationExample/

But when I try this URL:

http://localhost:8080/RestfulApplicationPathAnnotationExample/resources/hello

I get this error message:

HTTP Status 404 - /RestfulApplicationPathAnnotationExample/resources/hello

The requested resource (/RestfulApplicationPathAnnotationExample/resources/hello) is not available.

Can someone help me out please ?

Karthik
  • 315
  • 1
  • 4
  • 16
  • Please do **not** provide your code in images, but [edit] them into your question! Like that debugging can be done by friendly other users by copy pasting and not typing from your images! – geisterfurz007 Feb 01 '17 at 07:21

1 Answers1

0

WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2.”

This is a warning (not an error). You should not deploy any jar containg javax.servlet classes. Container will ignore it. Just remove javax.servlet-api-3.0.1.jar from your .war

About your path issue, seems jersey is omitting @ApplicationPath("resources"). Try to add / prefix like here @ApplicationPath("/resources")

Community
  • 1
  • 1
pedrofb
  • 37,271
  • 5
  • 94
  • 142