question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

using resource "./my-file" does not add the file to the classpath

See original GitHub issue

It 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:open
  • Created 2 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
tpasternakcommented, Nov 17, 2021

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 matching path. 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.

0reactions
tpasternakcommented, Nov 24, 2021

For handling resource files - it’s more complex but, maybe we can do it. Probably not right now

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found