perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.64k stars 1.56k forks source link

Spark cannot load static resources from jar files. #1074

Closed y-kaku closed 5 years ago

y-kaku commented 5 years ago

Spark cannot load static resources from jar files.

spark framework version

compile group:'com.sparkjava', name:'spark-core', version:'2.7.2'

code

staticFileLocation("/public");

gradle run on the console screen

2018-10-24 09:58:46,034 [INFO -spark.staticfiles.StaticFilesConfiguration] StaticResourceHandler configured with folder = /public

java -jar static-file-bug-1.0-SNAPSHOT-jar-with-dependencies.jar

nothing log
toyg commented 5 years ago

Works fine for me in 2.8.0 (although I use Maven). Have you checked the files are actually packed in the jar? Note also that they will be mounted in the URL at /, not /public -- that path is simply the folder in resources where Spark will look.

hoto commented 5 years ago

Also did you run init() to ignite the spark?

Static files location must be configured before route mapping. If your application has no routes, init() must be called manually after location is set.

source: http://sparkjava.com/documentation#static-files

perwendel commented 5 years ago

This has worked for a very long time and changes to this functionality has not been done in quite a while. Closing for now.