3

I'm very new to Spark. Will anyone please tell me how can I map external static resources? I am aware of the below method gotten from here :

public static synchronized void externalStaticFileLocation(String  
   externalFolder) {

 if (initialized) {
         throwBeforeRouteMappingException();
    }
     externalStaticFileFolder = externalFolder;
}

But I do not know how to use it. I called it before Routing like

externalStaticFileLocation("/resources/*");

I also tried

staticFileLocation("css/CrudTemp.css");
staticFileLocation("js/jquery.js");
staticFileLocation("js/jquery-ui.js");

Also tried

Spark.staticFileLocation("src/main/resources/css");
Spark.staticFileLocation("src/main/resources/js");
  • 1
    Duplicate of http://stackoverflow.com/questions/28125886/where-to-put-static-files-for-spark-web-framework – mtyson Oct 24 '15 at 22:56

1 Answers1

3

I solved it by Creating public folder under src/main/resources and then mapped it like

staticFileLocation("/public");

and then in template file i access that resources like

css/file.css
js/file.js

and it worked... but still i do not know why it did not worked for above methods described in questions

  • depending on your environment, you may need to add the resulting jar of your application to the classpath – Shujito Aug 23 '17 at 22:37