11.1 Locating Classpath Resources - Reference Documentation
Authors: Andres Almiray
Version: 1.2.0
11.1 Locating Classpath Resources
Resources can be loaded form the classpath using the standard mechanism provided by the Java runtime, that is, ask aClassLoader instance to load a resource URL or obtain an InputStream that points to the resource.But the code can get quite verbose, take for example the following view code that locates a text file and displays it on a text componentscrollPane {
textArea(columns: 40, rows: 20,
text: this.class.classLoader.getResource('someTextFile.txt').text)
}GriffonApplication and GriffonArtifact have a set of methods that simply working with resources. Those methods are provided by ResourceHandler:
URL getResourceAsURL(String resourceName)InputStream getResourceAsStream(String resourceName)List<URL> getResources(String resourceName)
scrollPane {
textArea(columns: 40, rows: 20,
text: app.getResourceAsURL('someTextFile.txt').text)
}