using resource "./my-file" does not add the file to the classpath
See original GitHub issueIt seems that the resource
directive has no effect on the classpath.
// using resource "./foo.txt"
// using scala 3.1.0
import scala.io.Source
@main def run() =
Source.fromInputStream(getClass.getResourceAsStream("/")).getLines().foreach(println)
$ ls
foo.txt using-resource.scala
$ scala-cli using-resource.scala
Compiling project (Scala 3.1.0, JVM)
Compiled project (Scala 3.1.0, JVM)
run.class
run.tasty
using$minusresource$package.class
using$minusresource$package.tasty
using$minusresource$package$.class
Note that foo.txt
is not part of the resources.
Expectation: foo.txt
is listed as a resource.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (10 by maintainers)
Top Results From Across the Web
File inside jar is not visible for spring - Stack Overflow
But using new ClassPathResource(filename).getInputStream() will solve this problem. The reason is that the configuration file in the jar does not exist in ...
Read more >How to Avoid the Java FileNotFoundException When Loading ...
In this quick article, we implemented loading files as classpath resources, to allow our code to work consistently regardless of how it was...
Read more >How to access static file in CloudHub - MuleSoft Help Center
Use the as resources from classpath. ... Put files to some folder - it will use not relative but absolute path as java...
Read more >Class path not loading from web-inf/classes - JBoss.org
getResource("/myfile.ext");. you will see that it is not a file://path/to/my/resource. If you're looking to ...
Read more >PATH and CLASSPATH - Bard College at Simon's Rock
The CLASSPATH is a variable that Java itself uses to keep track of where various classes are located that it might need. You...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey, I’m not sure if I understand this correctly, but it looks like calling
getClass.getResourceAsStream(path)
takes the first classpath entry containing a resource matchingpath
. If you pass “/” there, what matches anything, it will just take the first classpath entry no matter what it is.I’m not sure if we can do anything to handle this. I’d recommend to use
getClass.getClassLoader.getResources("")
if you want to look for resources in all cp paths.For handling resource files - it’s more complex but, maybe we can do it. Probably not right now