I have a working solution - Work-around, which I publish in the hope that this approach will inspire the right method. I still believe that there should be a way to specify the folder inside the JAR in relation to the JAR.
In any case, this method works. I used it for static web server content from a JAR. Essentially, I have Java allowing an absolute path to a running JAR resource and passing that Jetty path name. When I do this, Jetty displays my "helloWorld.html", a 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 placed specific text to determine the source of the file (in the resources folder). In browser:
Serves for the helloWorld.html file.
Displays a list of directories in the jar: / webapp / other / directory inside the JAR file. This depends on not changing the JAR while the server is running.
On Linux, if someone cp - adds a new jarfile on top of the running JAR, Jetty gives:
HTTP ERROR: 500 Problem accessing /. Reason: java.lang.NullPointerException
And you can no longer access the pages. This was unexpected (obviously, the JAR remains open). The good news is that if you are mv -s jarfile:
- mv fileserver.jar fileserverXX.jar
Jetty happily continues to work with the (renamed) fileserverXX.jar file. I can be satisfied with that. However, I would still like to know the equivalent relative path to match the absolute file name.
will
source share