Reputation: 967
I have a plugin project where I want to embedd jetty and display an index.html file that is in the project root folder.
I'm running this code:
Server server = new Server(8080);
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[]{ "index.html" });
resource_handler.setResourceBase(".");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
server.setHandler(handlers);
server.start();
server.join();
server.setStopAtShutdown(true);
I'm getting the Eclipse folder listed in the browser. I moved the index.html
to the eclipse folder and the problem was solved. But I want jetty to get the index.html
file from my project root folder and not from the Eclipse root folder. Can somebody help me?
Upvotes: 0
Views: 416
Reputation: 49462
The resource base should point to a path that is equivalent to your web-root.
Example:
resource_handler.setResourceBase("src/main/webroot");
Tip: It might make sense to base that path off of discovery of something else. A common technique is some logic to first look for the filesystem path of a class in your project's classloader, then building a resource path to your webroot relative to that discovered path.
Upvotes: 2