0

I'm developing a Scala tool under the SBT build system that depends on some resource files at runtime. The files are included in the normal src/main/resources directory. I successfully publish to my server and use it as a dependency in another project, but the files necessary for the tool to run are nowhere to be found!

find . -name <necessary_resource> within the project that depends on my tool finds nothing. It's clear then that sbt publish does not package up the resource files.

Is there a way to include the resources files whenever I publish the tool, or is there a different solution entirely to this problem?

Chris
  • 566
  • 2
  • 7
  • 22
  • 2
    The resource files are part of the JAR published. You have to assume they are in the classpath when reading them from code. – Gaël J Feb 21 '23 at 21:09
  • Does this answer your question? [How do I read a resource file from a Java jar file?](https://stackoverflow.com/questions/403256/how-do-i-read-a-resource-file-from-a-java-jar-file) – Gaël J Feb 21 '23 at 21:11
  • No, because the tool _requires_ that I be able to provide a path to the resource. It calls CLI tools that need to be able to use the resource as well. – Chris Feb 21 '23 at 21:15
  • Are the resource files separable from the `.jar`? Is there any way to reference them by name? – Chris Feb 21 '23 at 21:16
  • 1
    You'll need to extract the files from the JAR if your cli tool needs a file in the "regular" filesystem. If it's a java API it should be able to handle automatically path to a classpath resource. – Gaël J Feb 21 '23 at 21:17
  • That sounds hairy. It's not a java API. Is there any good way to do this? – Chris Feb 21 '23 at 21:20
  • 1
    I believe you'd need to share more details on the expected flow of execution. One solution could be that your program reads file from JAR and write it in a temporary file on disk and give this temporary file path to the CLI tool. – Gaël J Feb 21 '23 at 21:47
  • That's not a bad idea. I'll do that. Thank you. If you post it as an answer, I'll give you a check mark. – Chris Feb 21 '23 at 22:45

1 Answers1

1

Resource files are part of the published JAR.

These resource files will be available in the classpath when usong the JAR as a dependency.

One solution could be to:

Gaël J
  • 11,274
  • 4
  • 17
  • 32