dimanche 29 octobre 2017

Serving static content with Jersey

I have a sample web application in Jersey. I want to serve static content with it. The thing is I dont want to use web.xml and I have tried many configurations without any luck. Can someone please help? Here is my configuration.

ApplicationConfig.java

package com.zeeshanabid.jblog;

import com.zeeshanabid.jblog.controller.PostController; import org.glassfish.jersey.server.ResourceConfig;

import javax.ws.rs.ApplicationPath;

@ApplicationPath("/blog") public class ApplicationConfig extends ResourceConfig {

    public ApplicationConfig() {
        super(PostController.class);
        packages("com.zeeshanabid.jblog");
    }

}

IndexController.java

package com.zeeshanabid.jblog.controller;


import javax.ws.rs.GET;
import javax.ws.rs.Path;


@Path("/index")
public class IndexController {
    @GET
    @Path("/")
    public String index() {
       return "index.html";
    }
}

And I have a static file index.html in resources directory.

enter image description here

The whole repository is at this location. http://ift.tt/2iGAaUF

Any help is appreciated. Thanks a lot.




Aucun commentaire:

Enregistrer un commentaire