0

A lot of manuals say that canonical way to store resources is under resources folder in a project. The problem is that after assembling a project all of the resources are getting inside JAR. In my case resources are SQL scripts and I would like avoid assembling a new JAR if any SQL script changes. So I wish to supply resources in addition to JAR file. It will be tricky to access those files using typical methods for resources so the only way I can think of is considering them just as regular files in the file system (not resources as such).

Is is the right way to move forward? What are the possible alternative solutions.

Slimboy Fat
  • 157
  • 1
  • 1
  • 8
  • What specifically do you see as a difference between a "resource" and a "file on the file system"? – Dima Apr 30 '21 at 20:17
  • If you don't need them and don't ship them, why are they in the same project in the first place? Or did you intend to put them into `test/resources`? – Andrey Tyukin Apr 30 '21 at 20:22
  • You can read things from the file system. You can also add file system directories to your classpath when launching the application (then the normal resource loader will find them). But having everything in the jar file makes it much easier to deploy (and version!) applications, so it is unclear if you really want to go down that route. What's the issue with "assembling a new jar"? That should be just an `sbt assembly` run away. – Thilo May 01 '21 at 06:30
  • @Dima, resourses must be stored in specific location and they are getting inside fat jar by default. While if I do not consider my scripts as resources I can store them anywhere and access using `Source.fromFile` instead of `Source.fromResource`. – Slimboy Fat May 04 '21 at 10:25
  • @Andrey Tyukin, thanks for trying to help but I did not say anywhere that "I don't need them and don't ship them". My concern is how to ship resources of a project outside JAR in an arbitrary folder. – Slimboy Fat May 04 '21 at 10:27
  • @Thilo, when SQL developer modifies a scripts then releasing the change should be as simple as replacing a file. – Slimboy Fat May 04 '21 at 10:34
  • You can read things from the file system. You can also add file system directories to your classpath when launching the application (then the normal resource loader will find them). – Thilo May 04 '21 at 23:46

1 Answers1

0

It's possible to use SQL scripts as resources and ship them in a separate folder instead of JAR but probably it does not make sense. Since in such case it's much more reasonable to siply use files in the file system.

If, however, someone wants to do this trick then you need to

  1. Add that folder into CP so that you can access files as resources

https://www.scala-sbt.org/1.x/docs/Classpaths.html

https://docs.huihoo.com/sbt/0.12.4/Detailed-Topics/Classpaths.html

  1. Exclude resources from JAR

sbt-assembly: How do I exclude the configuration files in src/main/resources

Slimboy Fat
  • 157
  • 1
  • 1
  • 8