What is correct URL to specify ResourceBase of JAR "resources/webapp" folder for embedded Jetty?

I have a working solution - Work-around that I'm posting in the hope that this approach will inspire correct method. I still believe there ought to be a way to specify a folder inside the JAR, relative to the JAR.

Anyway this method works. I used it to server static web content from within the JAR. Essentially I have Java resolve the absolute path to the running JAR resource and pass that path name to Jetty. When I do that Jetty displays my "helloWorld.html", welcome file.

    String  baseStr  = "/webapp";  //... contains: helloWorld.html, login.html, etc. and folder: other/xxx.html
    URL     baseUrl  = SplitFileServerRunner.class.getResource( baseStr ); 
    String  basePath = baseUrl.toExternalForm();

      .... 
    resource_handler.setDirectoriesListed(true);      //... just for testing
    resource_handler.setWelcomeFiles(new String[]{ "helloWorld.html" });
    resource_handler.setResourceBase( basePath );
    LOG.info("serving: " + resource_handler.getBaseResource());

In the welcome file, I have put specific text to identify the file's origin (in the resources folder). In the browser:

  • localhost:8080

Serves the helloWorld.html file.

  • localhost:8080/other

Shows a directory listing of the jar:/webapp/other/ directory inside the JAR file. This relies on not changing the JAR while the server is running.

On Linux if someone cp-s a new jarfile on-top of the running JAR, Jetty gives:

 HTTP ERROR: 500

 Problem accessing /. Reason:

        java.lang.NullPointerException

And you can't access pages any more. That was unexpected (evidently the JAR is kept open). The good news is that if you mv-s the jarfile:

  • mv fileserver.jar fileserverXX.jar

Jetty happily continues serving from the (renamed) fileserverXX.jar content. I can be happy with that. However I'd still like to know the equivalent relative path to match the absolute file name.