java - Can't get resource files in my template files (using Restlet and Freemarker) -


i'm trying develop webapp restlet , have little problem access /public/css/* , /public/js/*.

i have messages in console :

info: 2012-03-10    23:52:59    127.0.0.1   -   -   8182    /public/css/bootstrap-responsive.min.css    -   404 439 0   0   http://localhost:8182   mozilla/5.0 (x11; linux x86_64) applewebkit/535.11 (khtml, gecko) ubuntu/11.10 chromium/17.0.963.65 chrome/17.0.963.65 safari/535.11   http://localhost:8182/hello 

i have helloworld using html template :

public class restletservertest extends serverresource {      public static void main(string[] args) throws exception {         component component = new component();         component.getservers().add(protocol.http, 8182);          component.getdefaulthost().attach("/hello", new helloworldapplication());          component.start();     } }  public class helloworldapplication extends application {     private configuration configuration;      @override     public synchronized restlet createinboundroot() {         configuration = new configuration();         try {             configuration.setdirectoryfortemplateloading(new file("src/main/webapp/web-inf/template"));             configuration.setobjectwrapper(new beanswrapper());         } catch (ioexception e) {             e.printstacktrace();         }          router router = new router(getcontext());          router.attach("", helloworldresource.class);          return router;     }      public configuration getconfiguration() {         return configuration;     } }  public class helloworldresource extends serverresource {     @get     public representation get() {         templaterepresentation templaterepresentation = new templaterepresentation("hello.ftl", getapplication()                 .getconfiguration(), mediatype.text_html);         return templaterepresentation;     }     @override     public helloworldapplication getapplication() {         return (helloworldapplication) super.getapplication();     } }  <!doctype html> <html>     <head>         <title>hello world</title>         <link rel="stylesheet" href="/public/css/bootstrap-responsive.min.css" />         <link rel="stylesheet" href="/public/css/bootstrap.min.css" />          <script type="text/javascript" src="/public/js/bootstrap.min.js"></script>     </head>     <body>         <h1>hello world</h1>     </body> </html> 

css , js files in "/src/main/webapp/public" folder. forgot something?

thank you.

florian.

perhaps can try use 1 of following classes: classtemplateloader or webapptemplateloader.

for example, can classtemplateloader class described below:

configuration configuration = new configuration(); configuration.settemplateloader(             new classtemplateloader(classintheclasspath.class,                             "/rootpath/under/classpath/"); configuration.setobjectwrapper(new defaultobjectwrapper()); (...) 

this allows finding templates in classpath under path /rootpath/under/classpath/. in context, first / root of classpath.

hope helps you. thierry


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -