Search code examples
javajettyspark-java

Can't load Spark static sub-directories


Here's my problem:

  • I'm using Spark as my web server framework in my Java project.
  • My website is designed with the following structure:
    • Index.html
    • js Folder (with JavaScript libraries and files)
    • css folder (with styles)
    • Image folder (with pics)

I copied this structure into my "public" folder (under resources) just like in the Spark documentation. and added this folder as a static folder using:

staticFiles.location("/public");
init();

But now, only the files inside "/public" and the immediate-childs of the folders can be accessed, i.e:

  • [localhost]:[port]/index.html - works
  • [localhost]:[port]/js/main.js - works
  • [localhost]:[port]/js/lib/lib.js - DOESN'T WORK - 404
  • [localhost]:[port]/css/myTheme/greenTheme.css - DOESN'T WORK - 404

What should I do to include all sub-directories as static files?

Thanks.

UPDATE: If I open a file that wasn't found in NetBeans, add a new line and saves the file - the file can later be found when I run the program! Any ideas for why's that?


Solution

  • If anyone ever encounter this issue - you should:

    1. clean your project.
    2. build it again.
    3. only then try to run it (clicking the Play button).

    Worked for me (using NetBeans IDE).