With Apache Jersey and Grizzly http server, how do I customize a basic template template?
Since I do not use the Servlet container, I assign a base template path with an absolute file path. But Jersey answered 404.
Below is my project setup
Project Directory :
src
└─ java
.....
└─ resources
└─ templates
└─ index.mustache
Application :
public class ExampleApplication extends ResourceConfig {
public CustomTableApplication() {
packages("com.example.app");
setupTemplateEngine();
}
private void setupTemplateEngine() {
property(MvcFeature.TEMPLATE_BASE_PATH, "/templates/");
register(MustacheMvcFeature.class);
}
}
Controller :
@Path("/")
public class Index {
@GET
@Template(name = "index")
public String index() {
return "";
}
}
How to create an HttpServer :
HttpServer server = new HttpServer();
NetworkListener listener = new NetworkListener("example", "localhost", 8080);
server.addListener(listener);
ServerConfiguration config = server.getServerConfiguration();
config.addHttpHandler(createJerseyHandler(), "/*");
source
share