Grails: getClass().getResource ("whatever") 不起作用

标签 grails resources classpath

如何在 Grails 中使用 getResource(String) 加载文件?

类和文件位置:

- grails-app
  - utils
    - MyClass.groovy
    - myfile.jks

通过以下内容我得到null

MyClass.class.getResource('myfile.jks')
MyClass.class.getResource('/myfile.jks')
MyClass.class.getResource('/grails-app/utils/myfile.jks')
MyClass.class.getResource('/utils/myfile.jks')

最佳答案

我通常会在类路径上的 grails-app/conf 目录中抛出类似的文件。那么你应该能够使用MyClass.class.getResource('/myfile.jks')

关于Grails: getClass().getResource ("whatever") 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11001501/

相关文章:

mysql_fetch_assoc() 参数 1 资源,对象在第 6 行 ... 中给出

JavaFX 资源处理 : Load HTML files in WebView

java - 使用 Jython 的标准 Python 模块的 ImportError(在 JAR 文件中)

java - 在 Spring 的 Classpath 中发现 Plugin-JARS

grails - Groovy中的随机枚举截断

Grails 在发生错误时重定向到页面

sorting - Grails:多个嵌套关系的分离标准

c# - 如何执行作为资源嵌入的可执行文件

Windows 上带有通配符的 java 类路径 : Requires semi-colon at the end

hibernate - 从重复名称列表中获取复杂的唯一变量