英文:
Which jar brings this resource file, in Databricks
问题
我正在 Databricks 中运行一个笔记本,使用一个安装了许多库的集群。
在代码中,我正在读取一个名为 files.txt
的资源文件,这是我刚刚安装的一个库的资源。
文件的行数比预期的要少。
我假设这个资源文件也在其他安装的 JAR 包中的一个中。
除了逐个手动下载已安装的 JAR 包并检查它们之外,是否有一种方法可以确定集群上安装的 JAR 包中包含了这个资源文件?
我这样读取文件:
val stream: InputStream = getClass.getResourceAsStream("/files.txt")
val lines: Iterator[String] = scala.io.Source.fromInputStream(stream).getLines
英文:
I am running a notebook in Databricks, on a cluster that has many libraries that were manually installed.
In code, I am reading a resource file files.txt
, which is a resource of a library I just installed.
The files has less lines than expected.
I'm assuming that the resource file is also in one of the other installed JARs.
Other than manually downloading the installed JARS, one by one, and examinig them - is there a way to tell which of the installed JARs on the cluster contains the resource file?
I'm reading the file like so:
val stream: InputStream = getClass.getResourceAsStream("/files.txt")
val lines: Iterator[String] = scala.io.Source.fromInputStream( stream ).getLines
答案1
得分: 2
getClass().getResource("/files.txt")
将返回一个URL,这应该会告诉您资源加载的位置。
英文:
getClass().getResource("/files.txt")
Will return an URL, this should tell you where the resource is loaded from
答案2
得分: 0
你可以通过从所有JAR包中调用以下代码来获取特定名称的资源列表:
getClass.getClassLoader().getResources("/files.txt")
如果存在冲突的资源,这将返回多个条目。
英文:
You can get the list of resources for a given name by calling from all jars
getClass.getClassLoader.getResources("/files.txt")
If you have conflicting resources, this will return several entries.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论