I'm trying to deploy a Jetty server from a jar file. When jar is being run on the server, it reaches the Jetty 404 page at least, but is unable to reach index.html
.
My main class to launch the server looks like this, and works fine locally when run through the IDE on localhost:
public static void main(String[] args) {
Server server = new Server(8080);
ServletContextHandler servletContextHandler = new ServletContextHandler(NO_SESSIONS);
servletContextHandler.setContextPath("/");
DefaultServlet defaultServlet = new DefaultServlet();
ServletHolder holderPwd = new ServletHolder("default", defaultServlet);
final URL htmlDirectory = JerseyApplication.class.getResource("/html");
holderPwd.setInitParameter("resourceBase", htmlDirectory.getFile());
servletContextHandler.addServlet(holderPwd, "/*");
server.setHandler(servletContextHandler);
ServletHolder servletHolder = servletContextHandler.addServlet(ServletContainer.class, "/api/*");
servletHolder.setInitOrder(0);
servletHolder.setInitParameter(
"jersey.config.server.provider.packages",
"com.x.y.z.parser");
try {
LOGGER.info("Starting server");
server.start();
server.join();
}
catch (Exception ex) {
LOGGER.error("Server failed to start - Aborting");
ex.printStackTrace();
}
finally {
LOGGER.info("Destroying server");
server.destroy();
}
}
All html stuff is in a the src/main/resources/html
directory.
When I run jar tvf jarfile.jar | grep html
I can see the html
directory and it's contents are in there:
0 Thu Nov 01 11:48:46 UTC 2018 html/
2258 Thu Nov 01 11:48:46 UTC 2018 html/formRequest.js
871 Thu Nov 01 11:48:46 UTC 2018 html/index.html
Thanks!