Search code examples
javarestmavenintellij-ideajersey

Jersey hello world displays nothing


I am new in rest web service with jersey, (with tomcat)

I have a HelloWorld source: (in the RestApp package)

package com.ss.hh;
...

@Path("/hello")
public class HelloWorld {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getMessage(){
        return "Hello jersey";
    }
}

And here is the web.xml:

<servlet>
    <servlet-name>jersey-serlvet</servlet-name>
    <servlet-class>
        com.sun.jersey.spi.container.servlet.ServletContainer
    </servlet-class>

    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.ss.hh</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>jersey-serlvet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

And in pom.xml:

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-server</artifactId>
    <version>2.19</version>
</dependency>

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-servlet</artifactId>
    <version>1.19</version>
</dependency>

Why i can't get the Hello jersey message in http://localhost:8080/hello?

UPDATE

I replace the jersey-servlet with jersey-container-servlet-core file and changed the web.xml configures as below:

<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.ss.hh</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

But it not displays anything on: http://localhost:8080/FirstRestApp/hello

FirstRestApp is the project name.


Solution

  • If the IDE is IntelliJ IDEA the URL should be like this:

    http://localhost:8080/hello
    

    (Without the project name)