Possible to use WebJars and static files with SparkJava?

185 views
Skip to first unread message

Ashley Hooper

unread,
Apr 28, 2017, 7:36:57 PM4/28/17
to sparkjava
Hi,
I'm having trouble with combining both WebJars and static files using Spark 2.5.5. I've done some googling and it appears other people have found this problematic also.


Also this earlier topic in this group:


My initial project layout was like this:

src
+-main
   +-java (Java packages below here)
   +-resources
      +-static
         +-css
         +-images
         +-js

I set staticFileLocation to /META-INF/resources, and was able to see the webjars/ subdirectory there (although the jQuery webjar was excluded - presumably due to a conflict), but of course my static files were not there because they were not available at /META-INF/resources

I then tried an alternative layout:

src
+-main
   +-java (Java packages below here)
   +-resources
      +-META-INF
         +-resources
            +-css
            +-images
            +-js

This led to my static files being available, but the webjars/ subdirectory was no longer there. I presume that the src/main/resources/META-INF/ path takes precedence over the webjars/ path?

Is there any clean/non-hacky way to combine webjars with static files in a Spark project?

Thanks,
Ashley


Wilson MacGyver

unread,
Apr 28, 2017, 8:01:50 PM4/28/17
to Ashley Hooper, sparkjava
I'm not sure what you mean by webjar

if you mean using spark to create a farjar, this works for me http://sparkjava.com/documentation.html#static-files


I create

src/main/resources/public/js/a.js

src/main/resources/public/css/a.css


in the main method, I put 

staticFiles.location("/public");


works for me both running the app, as well as generating a uber far and run it as
java -jar


 


--
You received this message because you are subscribed to the Google Groups "sparkjava" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sparkjava+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Omnem crede diem tibi diluxisse supremum.

Ashley Hooper

unread,
Jun 5, 2017, 1:20:15 AM6/5/17
to Wilson MacGyver, sparkjava
Sorry for the delay in replying.

Webjars are basically packaged versions of common javascript libraries that can be pulled in to a project via the pom.xml (Maven). More details are at http://www.webjars.org/

For the record, I've not had any problems including javascript, css, and other static files in my project.


Reply all
Reply to author
Forward
0 new messages