4

I'm trying to serve static content from my applications classpath using embedded jetty and I have written the following code

Server server = new Server(80);

ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
resourceHandler.setBaseResource(Resource.newClassPathResource("/"));
server.setHandler(resourceHandler);

server.start();
server.join();

If I run this code from my IDE (Intellij) everything works as expected, I get a directory listing of my classpath and can put html-files in my resource-directory

However, if I compile an executable jar-file using maven and maven-assembly-plugin to make a "jar-with-dependencies" and starting it with java -jar I'm met with the default jetty 404-page

So basically I'm trying to get the serving of static content to work and I'm really puzzled why this behaves differently when running to from the IDE vs command-line

Richo
  • 751
  • 7
  • 17
  • Are you running with maven in intellij or simple from the IDE itself? Also which version of Jetty are you using? – Mark Butler Jun 22 '14 at 20:22
  • When I start it from the IDE I'm not using maven. Jetty version 9.2.1.v20140609 – Richo Jun 22 '14 at 20:27
  • It seems like a security issue to me. I.e. Access to files inside the JAR is being blocked. What exactly are you trying to achieve here? – Mark Butler Jun 22 '14 at 21:52
  • I want an executable jar that can run servlets and serve static html and javascript-files that are in my resource-directory and I'm trying to achieve that using jetty. So basically I want to do webapps without having to run tomcat or jetty standalone – Richo Jun 23 '14 at 12:45

0 Answers0