We want a simple embedded Jetty servelet with the web resources inside a JAR-file's resources folder. We have some properties files in the JAR and load them using a resources path. We want to specify the Jetty Resource Base to be:
- resources/webapp
- set: resource_handler.setResourceBase( "webapp" )
- Via the correct URL to point to that resource in the JAR file.
Folder in the JAR file. This is a bare bones JAR file (not WAR, no frameworks, without Spring, as vanilla as we may). Initial tests continue to throw exceptions for something like the following strings:
webPath = "jar:file:!/webapp"; //.... runs the Jetty server
...
resource_handler.setResourceBase( webPath );
Although the server seems to run, the result fails to find my index.html. (Update:) This example is just taking from the Jetty "Embedded File Server" example. In this case, the requirement is for the Jetty Resource Base to map to the JAR file (full-URL):
- "jar:file:!/webapp/index.html",
as follows:
- resource_handler.setResourceBase("jar:file:!/webapp");
Instead of the example given:
- resource_handler.setResourceBase(".");
And we want this to map the browser URL as:
- localhost:8080/index.html
- ... giving ...
- jar:file:!/webapp/index.html
For contrast the JAR path that work for config files below. The question: what should the URL be so Jetty resource base can serve-up my Index.html file?
- resources/
- config/
- display.properties
- config/
file is: "/config/display.properties" and this works in the same project code using a load resources operation. The layout is like this:
app.jar
+----- com /
| +--- ( classes ... )
|
+----- config /
| |
| +--- display.properties
|
+----- webapp /
|
+--- index.html
To give the general idea.
similar questions:
http://localhost:8080/index.html
? When jar runs. – Baltoslavicresource_handler.setResourceBase(this.class.getClassLoader().getResource("/webapp").toExternalForm());
See docs.codehaus.org/display/JETTY/Embedding+Jetty – Baltoslavic