spark: Could not load static resources from jar files
I can package all my static resources into a jar file, when I used version 2.3. But after I update my spark to the latest version of master branch, it does not work.
2016-04-30 09:54:02,147 [main] ERROR spark.staticfiles.StaticFilesConfiguration[116] - Error when creating StaticResourceHandler
java.io.FileNotFoundException: class path resource [public] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/home/towerhe/Repository/Codes/maoguang/java/mg-vdra/standalone/target/mg-vdra-standalone-0.1.0-SNAPSHOT/lib/mg-vdra-core-0.1.0-SNAPSHOT.jar!/public
at spark.utils.ResourceUtils.getFile(ResourceUtils.java:213) ~[spark-core-2.4-SNAPSHOT.jar:na]
at spark.resource.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:46) ~[spark-core-2.4-SNAPSHOT.jar:na]
at spark.staticfiles.StaticFilesConfiguration.configure(StaticFilesConfiguration.java:105) ~[spark-core-2.4-SNAPSHOT.jar:na]
at spark.Service.staticFileLocation(Service.java:208) [spark-core-2.4-SNAPSHOT.jar:na]
at spark.Spark.staticFileLocation(Spark.java:977) [spark-core-2.4-SNAPSHOT.jar:na]
at org.maoguang.vdra.Application.init(Application.java:26) [mg-vdra-core-0.1.0-SNAPSHOT.jar:na]
at org.maoguang.vdra.Main.run(Main.java:31) [mg-vdra-core-0.1.0-SNAPSHOT.jar:na]
at org.maoguang.vdra.Main.main(Main.java:54) [mg-vdra-core-0.1.0-SNAPSHOT.jar:na]
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 3
- Comments: 18 (13 by maintainers)
Commits related to this issue
- Fix for #535. Static files in jar — committed to perwendel/spark by perwendel 8 years ago
- Merge pull request #537 from perwendel/pw-static-files-jar-solution Fix for #535. Static files in jar — committed to perwendel/spark by perwendel 8 years ago
A remark here that could save some time for future people still running in
Error when creating StaticResourceHandler
with spark > 2.5 : the folder invocation must start with a “/” so:Spark.staticFileLocation("/public");
works both in IntelliJ and in a jar whileSpark.staticFileLocation("public");
works only in IntelliJI am running into a similar issue as well, even though I am running 2.5 and am using “/static” as my static folder. Works fine in IDE but not as a jar. I traced through it and it throw an IOException in StaticFilesConfiguration at this line: if (resource.getURL().getProtocol().equals(“jar”)) {
Any other idea how to get around this?