Hi Robert, I send you a zip file of the eclipse project (testRobert.zip), and the jar file generated by eclipse. I launch the application on command line as follow: java -cp testRobert.jar:/home/thierry/restlet/branches/2.1/org.restlet.jar test.MyApplication
Best regards, Thierry Boileau 2013/1/11 Robert Brewer <rbre...@lava.net> > Hmm, I could not clap and jars for a directory to work. Do you have > the test code that worked available? I will try reducing my code to a > bare minimum to see what is going on, but another project has come up > so I have to investigate later. > > Thanks for your help. > > On Wed, Jan 9, 2013 at 10:36 PM, Thierry Boileau <tboil...@restlet.com> > wrote: > > Hi Robert, > > > > I've just tried the clap connector using a jar file and it works for me > (I > > mean such url works : "http://localhost:8182/stat/index.html", > > "http://localhost:8182/stat/"). Just take care to complete properly the > > classpath when lauching your application from the command line. > > > > Best regards, > > Thierry Boileau > > > > > > 2013/1/10 Thierry Boileau <tboil...@restlet.com> > >> > >> Hello Robert, > >> > >> from what I notice, the resolution of "a file" is more or less based on > >> the ability to discover ressources having the same base name. A file > >> directory is perfect because it is possible to list all ressources > within > >> the same parent directory. > >> A classloader is more retrictive and gives access to a single > resource... > >> which explains the behaviour of the "indexName" attribute of a > Directory. > >> I check why it does not work from a jar file. > >> > >> You can also connect the Directory with the jar file using the JAR > >> protocol or the ZIP protocol. Such protocol is based on the JDK ZipEntry > >> class which has the ability to list files (such as a directory). > >> directory = new Directory(getContext(), "zip:" + > >> LocalReference.createFileReference(new File("/your/path")) + "!/" ); > >> Of course, it obliges you to reference the jarfile from itself. You can > >> consider this as a workaround. > >> > >> Best regards, > >> Thierry Boileau > >> > >> > >> 2013/1/10 Robert Brewer <rbre...@lava.net> > >>> > >>> Hello Restlet folks. I have a problem serving static files using > >>> Restlet's Directory class and the CLAP pseudo protocol (apparently a > >>> popular topic right now :) > >>> > >>> I have a standalone web application that uses Restlet to provide a > >>> RESTful API. Some students taking a class have written a nice client > >>> for the web application as a Single Page Application (SPA) consisting > >>> of HTML5/CSS/Javascript. I would like to store a directory containing > >>> the static SPA files in my web application's jar file and to serve > >>> them under a specific URI so the SPA client and server are > >>> self-contained > >>> > >>> The way I am trying to do this is: > >>> > >>> public synchronized Restlet createInboundRoot() { > >>> ... > >>> Directory directory = new Directory(getContext(), > >>> "clap://class/spa/"); > >>> router.attach("/spa/", directory); > >>> ... > >>> > >>> Unfortunately, this doesn't work. When I run the server from my jar > >>> file and point a browser at "/spa/", the browser downloads an empty > >>> file (Chrome calls it "download", Safari calls it "spa") rather than > >>> rendering the page. Browsing to "/spa/index.html" does work, but I > >>> don't want users to have to remember to add the "index.html". > >>> > >>> Am I doing something wrong here? It seems like this should work. I'm > >>> open to other ways to accomplish this goal. > >>> > >>> Annoyingly, the server behaves differently when running from Eclipse > >>> than when running from a jar file, which makes troubleshooting this > >>> problem more painful since I have to build the jar file to test > >>> fixes.For example, when running from Eclipse, "/spa/" gives a 404 > >>> error, instead of downloading an empty file. > >>> > >>> I also tried playing with setIndexName(). If I set it to "index.html" > >>> (including the extension despite the Javadoc saying the parameter > >>> should be without extension), then it works when run from Eclipse but > >>> not from the jar file. > >>> > >>> Thanks in advance for any suggestions on how to make this work! > >>> > >>> -- > >>> Robert Brewer > >>> http://excitedcuriosity.wordpress.com/ > >>> https://www.facebook.com/kukuicup > >>> > >>> ------------------------------------------------------ > >>> > >>> > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3042270 > > -- > Robert Brewer > http://excitedcuriosity.wordpress.com/ > https://www.facebook.com/kukuicup > > ------------------------------------------------------ > > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3042617 > ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3042664
testRobert.jar
Description: application/java-archive