如何通过使用Scalatra的sbt-assembly创建包含Webapp资源的可执行单个jar [英] How to create executable single jar which include webapp resources by sbt-assembly with scalatra

查看:104
本文介绍了如何通过使用Scalatra的sbt-assembly创建包含Webapp资源的可执行单个jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过sbt& xsbt-web-plugin.

I'm making webapp using scalatra framework via sbt & xsbt-web-plugin.

我想将所有资源(模板,css,js)打包到一个jar中.

I want to package all resources(templates, css, js) into a single jar.

在带有sbt-assembly插件的sbt中,assembly命令使单个jar包含项目的所有依赖项.

In sbt with sbt-assembly plugin, assembly command makes single jar which includes all of project's dependencies.

$ java -jar myproject.jar

然后在浏览器中打开它

无法加载资源:[/WEB-INF/views/index.scaml];您确定它在[null]内吗?

Could not load resource: [/WEB-INF/views/index.scaml]; are you sure it's within [null]?

我解压缩了罐子以确认它不包含src/main/webapp/*.

I unzipped jar to confirm that it does not include src/main/webapp/*.

如何配置sbt以包括src/main/webapp/*并构建可执行jar?

How can I config sbt for including src/main/webapp/* and building executable jar?

推荐答案

资源应放置在文件夹下.有两个这样的文件夹:

Resources are meant to be put under the resources folders. There are two such folders:

  • src/main/resources获取运行时可用的资源
  • src/test/resources获取仅在测试期间可用的资源
  • src/main/resources for resources available at runtime
  • src/test/resources for resources available only during testing

sbt将在您运行package-wartest时自动为您打包这些文件.该项目不需要sbt的程序集插件即可包含资源.

sbt will package those automatically for you when you run package-war or test. The project does not need to have the assembly plugin for sbt to include resources.

在这种情况下,应将WEB-INF目录放在src/main/resources/WEB-INF/中.

In your case, you should put the WEB-INF directory in src/main/resources/WEB-INF/.

这篇关于如何通过使用Scalatra的sbt-assembly创建包含Webapp资源的可执行单个jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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