在哪里放置静态文件的Spark Web框架? [英] Where to put static files for Spark Web Framework?

查看:238
本文介绍了在哪里放置静态文件的Spark Web框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我无法在线上找到任何东西 - 我开始了怀疑我不明白Eclipse和Java项目的类路径,相对路径等。



关于Spark中的静态文件的这一段是指 / public ,但我不知道在哪里那将是。使用Windows,Eclipse Luna和我的项目被转换为使用Maven。



我试过看过GitHub上的代码,但是我有点不在我的深度尝试找到它。

解决方案

首先你必须告诉Spark在哪里搜索这样的静态文件:

  Spark.staticFileLocation(/ public); 

那么你的项目应该有一个 public 在这样的资源文件夹下



/src/main/resources/public/style.css



例如,我在这里添加了一个 style.css 文件,所以你应该这样访问:



http:// localhost:4567 / style.css


Where do I put files when trying to serve static files with the Spark web framework?

I haven't been able to find anything online - I'm beginning to suspect I don't understand anything about class paths, relative paths etc. for an Eclipse and Java project.

This paragraph about static files in Spark refers to /public, but I have no idea where that would be. Using windows, Eclipse Luna and my project is converted to use Maven.

I've tried looking at the code on GitHub, but I'm a little out of my depth trying to find it.

解决方案

First you have to tell Spark where to search for the static files like this:

Spark.staticFileLocation("/public");

Then your project should have a public folder under the resources folder like this

/src/main/resources/public/style.css

For example I added a style.css file there, so you should then access it like this:

http://localhost:4567/style.css

这篇关于在哪里放置静态文件的Spark Web框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆