This should be fairly easy, but for some reason nearly everything I try just seems to hand out a 'not found' error when I hook it up to a web browser.
I've got a single static context, and for the ResourceBase I've got 'file:jar:/path/to/myjar!/.'... any ideas what I'm missing?
There are three steps to requesting static content from a server: A user sends a request for a file to the web server. The web server retrieves the file from disk. The web server sends the file to the user.
The context path is the prefix of a URL path that is used to select the web application to which an incoming request is routed. Typically a URL in a Java servlet server is of the format http://hostname.com/contextPath/servletPath/pathInfo, where each of the path elements may be zero or more / separated elements.
The Eclipse Jetty Project Jetty provides a web server and servlet container, additionally providing support for HTTP/2, WebSocket, OSGi, JMX, JNDI, JAAS and many other integrations. These components are open source and are freely available for commercial use and distribution.
In terms of licensing, Tomcat enjoys the Apache 2.0 open source license, while Jetty is dual licensed through both the Apache 2.0 License and the Eclipse Public License 1.0.
Try to load the resource from classloader like this,
ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = getClass().getClassLoader();
}
InputStream stream = classLoader.getResourceAsStream(name);
Your approach assumes absolute path and it may not be true when the server is deployed. The jar could be in another JAR (WAR) or a temporary directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With