Instead of trying to piece together a url, either let the jvm or jetty take care of that for you.
jvm: use Paths.get(webroot).toAbsolutePath().toURI().toURL() and you'll get the url jetty: use the Resource class instead: Resource.newResource(webroot). Then if you need a url, Resource.getURL(). Jan On 3 January 2017 at 22:24, Carl-Erik Kopseng < [email protected]> wrote: > I modified the embedded-jetty project > <https://raw.githubusercontent.com/jetty-project/embedded-jetty-jsp/master/src/main/java/org/eclipse/jetty/demo/Main.java> > to > create a stand-alone jsp-viewer > <https://github.com/fatso83/jsp-viewer/blob/master/src/main/java/com/github/fatso83/jspviewer/Main.java> > that > should be able to serve any directory containing jsps, not just the ones > embedded in a jar file. *The resulting jar works fine on macOS and Linux.* > > What I discovered is that *it does not work on Windows* - for some reason > that escapes me, although the logs indicate that it resolved the directory > just fine. I have enabled the "dirAllowed"property to list directory > contents, yet I consistently get this error no matter the directory or file: > > HTTP ERROR 404 > Problem accessing /. Reason: > > Not Found > > I ripped out a lot of unneeded code, but I believe the main difference > between my project on the demo project from Jetty is this diff that shows > how my project references a webroot property as the directory to serve, > instead of a hard coded path in the jar file in the original > > > String userDir = System.getProperty("webroot");> String > > webroot = (userDir != null && userDir.length() > 0)? userDir : ".";> > > webroot = Paths.get(webroot).toAbsolutePath().normalize().toString(); > > and this > > < URL indexUri = this.getClass().getResource(WEBROOT_INDEX);> > URL indexUri = new URL("file://" + webroot); > > I have tried serving various folders to see if it is some kind of > permission issue, but I don’t get anywhere with this. I still get a 404 on > Windows no matter what. > > *Output from console when running on macOS* > > ./jsp-viewer/view-jsp /tmp2017-01-02 15:53:50.456:INFO::main: Logging > initialized @124ms to org.eclipse.jetty.util.log.StdErrLog > jan 02, 2017 3:53:50 PM com.github.fatso83.jspviewer.Main defaultServletHolder > INFO: Base URI: file:/tmp2017-01-02 15:53:50.574:INFO:oejs.Server:main: > jetty-9.4.z-SNAPSHOT2017-01-02 15:53:50.737:INFO:oejs.session:main: > DefaultSessionIdManager workerName=node02017-01-02 > 15:53:50.737:INFO:oejs.session:main: No SessionScavenger set, using > defaults2017-01-02 15:53:50.740:INFO:oejs.session:main: Scavenging every > 660000ms2017-01-02 15:53:50.756:INFO:oejsh.ContextHandler:main: Started > o.e.j.s.ServletContextHandler@6d8a00e3{/,file:///tmp/,AVAILABLE}2017-01-02 > 15:53:50.779:INFO:oejs.AbstractConnector:main: Started > ServerConnector@457e2f02{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}2017-01-02 > 15:53:50.779:INFO:oejs.Server:main: Started @451ms > jan 02, 2017 3:53:50 PM com.github.fatso83.jspviewer.Main getServerUri > INFO: Server URI: http://localhost:8080/ > > *Output on Windows (Mingw)* > > $ ./jsp-viewer/view-jsp /tmp/2017-01-02 16:12:15.541:INFO::main: Logging > initialized @266ms to org.eclipse.jetty.util.log.StdErrLog > jan 02, 2017 4:12:18 PM com.github.fatso83.jspviewer.Main defaultServletHolder > INFO: Base URI: file://C:/Users/SA_CAR~1.KOP/AppData/Local/Temp/22017-01-02 > 16:12:18.106:INFO:oejs.Server:main: jetty-9.4.z-SNAPSHOT2017-01-02 > 16:12:18.449:INFO:oejs.session:main: DefaultSessionIdManager > workerName=node02017-01-02 16:12:18.450:INFO:oejs.session:main: No > SessionScavenger set, using defaults2017-01-02 > 16:12:18.454:INFO:oejs.session:main: Scavenging every 600000ms2017-01-02 > 16:12:18.475:INFO:oejsh.ContextHandler:main: Started > o.e.j.s.ServletContextHandler@24a67{/,file://C/Users/SA_CAR~1.KOP/AppData/Local/Temp/2,AVAILABLE}2017-01-02 > 16:12:18.515:INFO:oejs.AbstractConnector:main: Started > ServerConnector@feb3fa{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}2017-01-02 > 16:12:18.530:INFO:oejs.Server:main: Started @3261ms > jan 02, 2017 4:12:18 PM com.github.fatso83.jspviewer.Main getServerUri > INFO: Server URI: http://localhost:8080/ > > > > // carl-erik > > > _______________________________________________ > jetty-users mailing list > [email protected] > To change your delivery options, retrieve your password, or unsubscribe > from this list, visit > https://dev.eclipse.org/mailman/listinfo/jetty-users > -- Jan Bartel <[email protected]> www.webtide.com *Expert assistance from the creators of Jetty and CometD*
_______________________________________________ jetty-users mailing list [email protected] To change your delivery options, retrieve your password, or unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/jetty-users
